Skip to main content
Solved

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


Forum|alt.badge.img
  • Semi-Pro II
  • 247 replies

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.

Best answer by andriitkachenko

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.

View original
Did this topic help you find an answer to your question?

5 replies

Nilkanth Dipak
Semi-Pro I
Forum|alt.badge.img+10

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!


RohitRattan88
Acumatica Moderator
Forum|alt.badge.img+4
  • Acumatica Moderator
  • 253 replies
  • July 29, 2024

@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 πŸ˜Š


Forum|alt.badge.img
  • Author
  • Semi-Pro II
  • 247 replies
  • July 30, 2024
Dipak Nilkanth wrote:

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?


Nilkanth Dipak
Semi-Pro I
Forum|alt.badge.img+10

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!


andriitkachenko
Jr Varsity I
Forum|alt.badge.img+6

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings