Skip to main content
Solved

How can I add an Employee ID selector on the line level?

  • 29 July 2024
  • 5 replies
  • 75 views

Hello,

How can I add a new column for Employee ID selector field on the Line level of Invoices & Memos (AR301000) → Details tab. So when the user would manually select the Employee ID the system should automatically fill in the Employee Name in a second new column.

 

Thanks.

Hi @Harry ,

you need to create 2 new custom fields to the ARTran extension DAC, one for selector and one for display employee name.

then you need to declare field updated event for the selector field and write logic to display employee name based on selection.
 

  protected void ARTran_UsrCustomEmployeeID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (ARTran)e.Row;
if (row == null) return;

var ext = PXCache<ARTran>.GetExtension<ARTranExt>(row);

if (ext.UsrCustomEmployeeID!= null)
{
EPEmployee employee = PXSelect<EPEmployee,
Where<EPEmployee.bAccountID, Equal<Required<EPEmployee.bAccountID>>>>
.Select(cache.Graph, ext.UsrEmployeeID);

if (employee != null)
{
ext.UsrCustomEmployeeName = employee.AcctName;
}
}
else
{
ext.UsrCustomEmployeeName = null;
}
}

Hope, it helps!


@Harry 

How to add custom EmployeeID field: How to add "employee selector" on Shipment screen? | Community (acumatica.com)

How to autofill Employee Name based on selected EmployeeID field: graph - Make a form field selection values dependent on another field value - Stack Overflow

Hope it helps 😊


Hi @Harry ,

you need to create 2 new custom fields to the ARTran extension DAC, one for selector and one for display employee name.

then you need to declare field updated event for the selector field and write logic to display employee name based on selection.
 

  protected void ARTran_UsrCustomEmployeeID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (ARTran)e.Row;
if (row == null) return;

var ext = PXCache<ARTran>.GetExtension<ARTranExt>(row);

if (ext.UsrCustomEmployeeID!= null)
{
EPEmployee employee = PXSelect<EPEmployee,
Where<EPEmployee.bAccountID, Equal<Required<EPEmployee.bAccountID>>>>
.Select(cache.Graph, ext.UsrEmployeeID);

if (employee != null)
{
ext.UsrCustomEmployeeName = employee.AcctName;
}
}
else
{
ext.UsrCustomEmployeeName = null;
}
}

Hope, it helps!

Hello @Dipak Nilkanth ,
What if I am looking to display the Employee ID and name in one field only?


Hi @Harry ,

I believe you will not be able to display both values in the selector field. However, you can display the concatenated values in the UsrCustomEmployeeName field by combining the two values.

protected void ARTran_UsrCustomEmployeeID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (ARTran)e.Row;
if (row == null) return;

var ext = PXCache<ARTran>.GetExtension<ARTranExt>(row);

if (ext.UsrCustomEmployeeID != null)
{
EPEmployee employee = PXSelect<EPEmployee,
Where<EPEmployee.bAccountID, Equal<Required<EPEmployee.bAccountID>>>>
.Select(cache.Graph, ext.UsrCustomEmployeeID);

if (employee != null)
{
ext.UsrCustomEmployeeDisplay = $"{employee.AcctCD} - {employee.AcctName}";
}
else
{
ext.UsrCustomEmployeeDisplay = null;
}
}
else
{
ext.UsrCustomEmployeeDisplay = null;
}
}

hope, it helps!


Hi @Harry 

It sounds like you want to add a custom selector for your new field:

         PXSelector(typeof(Search<EPEmployee.bAccountID>),
typeof(EPEmployee.bAccountID),
typeof(EPEmployee.acctCD),
typeof(EPEmployee.acctName),
SubstituteKey = typeof(EPEmployee.acctName))]

You probably need to tinker a bit with the fields you show in the selector, but this should give you the idea.  

SubstituteKey allows you to define what field value will be shown, and the value in the first parameter (typeof(Search<EPEmployee.bAccountID>) in the example) will define the real value underneath. Parameters after Search are responsible for fields shown in selector columns, add/remove them as you like.

Put this selector on your new custom field, add it to the grid and it should be enough - no additional events or 2nd field required.


Reply