web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to create a Responsible User lookup in D365 F&O that shows both Employees and Non-Employees?

(5) ShareShare
ReportReport
Posted on by 198

Hi,

I am customizing the Asset form in D365 F&O.

Requirement: Add a Responsible User lookup field where:

If UserType = Employee, the lookup should display records from HcmWorker.

If UserType = NonEmployee, the lookup should display records from a custom table CIMDTNonEmployee (Name, CompanyName, NonEmployeeType).

I created a new field CIMDTResponsibleUser on EntAssetObjectTable and added it to the form.

I tried writing an OnLookup event handler but I’m not sure how to switch between Worker and NonEmployee tables properly.

Code Tried:

 
[FormControlEventHandler(formControlStr(EntAssetObjectTable, CIMDTResponsibleUser), FormControlEventType::Lookup)]
public static void CIMDTResponsibleUser_OnLookup(FormControl sender, FormControlEventArgs e)
{
super();
}

Question:

How can I implement a lookup that dynamically switches between HcmWorker and CIMDTNonEmployee based on the UserType enum?

1.png
Categories:
I have the same question (0)
  • R Shetty Profile Picture
    121 on at
    Hi Aditya,

    You can use condition and write the code. 
    For ex, something like this
    {
       Query                               query           =   new Query();
            QueryBuildDataSource                qbds, qbds1;
            FormControlCancelableSuperEventArgs cancelableArgs = e as FormControlCancelableSuperEventArgs;
            
    If(table.field = type::employee)
    {
            SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(HcmWorker), sender);
            qbds    =   query.addDataSource(tableNum(HcmWorker));
            sysTableLookup.parmQuery(query);
            sysTableLookup.addLookupfield(fieldNum(HcmWorker, field1));
            sysTableLookup.addLookupfield(fieldNum(HcmWorker, field2));
           
            sysTableLookup.performFormLookup();
            cancelableArgs.CancelSuperCall();
    }
    
    Else If(table.field = type::NonEmployee)
    {
            SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(CIMDTNonEmployee ), sender);
            qbds1    =   query.addDataSource(tableNum(CIMDTNonEmployee ));
            sysTableLookup.parmQuery(query);
            sysTableLookup.addLookupfield(fieldNum(CIMDTNonEmployee , field1));
            sysTableLookup.addLookupfield(fieldNum(CIMDTNonEmployee , field2));
           
            sysTableLookup.performFormLookup();
            cancelableArgs.CancelSuperCall();
    }
    
    }
     
  • Aditya Pal Profile Picture
    198 on at
     
    =
    R Shetty
     

    I have created a custom string field called CIMDTResponsibleUser in my table/form.

    I want this field to open the HcmWorker form as a lookup, so the user can select a worker.

    How can I achieve this in D365 Finance & Operations?

  • Suggested answer
    Waed Ayyad Profile Picture
    9,089 Super User 2026 Season 1 on at
    Hi,
     
    In order to add lookup to control via extension, you should follow the following link:
    https://ievgensaxblog.wordpress.com/2018/01/10/d365foe-how-to-override-form-data-source-field-lookup-method/
     
    Or you can override it using event handler, but you should use CancelSuperCall method as in the following link:
     

     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at
    A worker could be employee or contractor. 
    Have you seen how the worker lookup is being used on the Sales Order form?
  • Aditya Pal Profile Picture
    198 on at
    [FormControlEventHandler(formControlStr(EntAssetObjectTable, CIMDTResponsibleUser), FormControlEventType::Lookup)]
    public static void CIMDTResponsibleUser_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormControlCancelableSuperEventArgs cancelableArgs = e as FormControlCancelableSuperEventArgs;
        Args      args = new Args();
        FormRun   formRun;
        // Set form to open
        args.name(formStr(HcmWorkerLookup));
        args.caller(sender);
        // Force popup by setting window mode in args
        args.parmEnumType(enumNum(FormWindowType));
        args.parmEnum(enum2int(FormWindowType::Popup));
        // Create and run form
        formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.wait();
        // Stop default lookup
        cancelableArgs.cancelSuperCall();
    } I have done this but it is not comeing as pop
     
  • Aditya Pal Profile Picture
    198 on at

    I have a standard lookup on my AllAsset form for the ResponsibleUser field. Currently, it works for Employee and Contractor types. I want to extend it as follows:

    Keep the existing ranges for Employee and Contractor as they are.

    Add a new type called Non-Employee. When this is selected, the lookup should show data from my custom table (CIMDTNonEmployeeTable) instead of the standard Employee table.

    The lookup should behave exactly like the standard one for Employee and Contractor.

    I tried overriding the OnLookup method, but I’m not sure how to conditionally switch the datasource based on the selected type and keep the standard behavior intact for other types.

    Question:

    How can I implement a conditional lookup in D365 X++ that:

    Uses the standard table for Employee and Contractor

    Uses my custom table for Non-Employee

    Keeps standard lookup behavior otherwise

     

     

  • Suggested answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at
    For standard systems, employees and contractors are the same from the back-end, as the data for both is saved in a single table, which is the HCMWorker table.
    In your case, you are talking about adding a new option that would show data from your custom table named CIMDTNonEmployeeTable.
    This would break the reference data, because as of now, you probably have a relationship between AssetTable and HCMWorker using the RecId of HCMWorker.
    You cannot save the RecId of CIMDTNonEmployeeTable in the same field where you are saving the HCMWorkerRecId (in AssetTable). This is because the field that is saving your HCMWorkerRecId in AssetTable is backed by an EDT and a relationship with the HCMWorker table.
     
    You have two options:
     
    1) Remove the reference and relationships, and save data for all references into a single field, and then maintain a second field for TableId
    or
    2) Save the data for the second reference in a new field, which will store the RecId of CIMDTNonEmployeeTable in AssetTable.
     
    Without solving the database design, you should not think about the lookup.
     
  • Aditya Pal Profile Picture
    198 on at
    What will happen if I remove the reference and relation? Then I will not be able to see the worker lookups right?

    If I go with saving data in another field how will it work in same lookup? Can you please guide for this
  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at
    I see a possibility of custom lookup in both cases. 
    All depends upon how you want to keep data in Asset Table and how you want to utilize it, we do not know what is CIMDTNonEmployeeTable and what is the use of it and how it is linked to other objects in the system. 
    You could also think about making a single view using HCMWorker and CIMDTNonEmployeeTable and then use it for lookup.
    It is hard for us to give a final design suggestion to, as we do  not know your customization and business needs., 
  • Aditya Pal Profile Picture
    198 on at

    Hi all,

    I am working on the AllAsset form in D365 F&O. I have a new requirement:

    There is an enum field ResponsibleUserType with values Employee and Non-Employee

    There is a field ResponsibleUser. The lookup on this field should behave based on ResponsibleUserType:

    If Employee is selected → show the standard HcmWorker lookup form (HcmWorkerLookup).

    If Non-Employee is selected → show a custom lookup from my table CIMDTNonEmployeeTable.

    I want to implement this without breaking the existing HcmWorker relationships, and ensure the lookup behaves correctly for both Employee and Non-Employee.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans