Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

How to get Employee name in my field by selecting lookup with employee Name and employee Id

Posted on by 170

Hi there,

I have a requirement

I need to get employee name in my field and that field has lookup with employee name and employee id, when i select a record from that lookup then employee name has to sit in my field as value.

I have written this code and i'm getting lookup with employee id and employee name but while selecting employee id is getting in my field as value but i want employee name

My field Validation -User input - Use Drop Down from Employee Master showing Emp. Number and Name and select employee name

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HcmWorker), sender);


Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildDataSource qbdsJoin,qbdsJoin1;


qbds= query.addDataSource( tableNum(HcmWorker));

qbdsJoin= qbds.addDataSource( tableNum(DirPerson));
qbdsJoin.relations( true);


sysTableLookup.parmQuery(query);
sysTableLookup.addLookupfield( fieldNum(HcmWorker,PersonnelNumber ),true);
sysTableLookup.addLookupMethod(tableMethodStr(HcmWorker,Name));
sysTableLookup.performFormLookup();

Thank you.

  • Ganesh Potnuru Profile Picture
    Ganesh Potnuru 170 on at
    RE: How to get Employee name in my field by selecting lookup with employee Name and employee Id

    Thanks Gunjan Bhattachayya

    I got it, I used this onlookup event

    Query query = new Query();

           QueryBuildDataSource queryBuildDataSource;

           QueryBuildRange queryBuildRange;

           SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HcmWorker), sender);

           sysTableLookup.addLookupField(fieldNum(HcmWorker,PersonnelNumber));

           sysTableLookup.addLookupMethod(tableMethodStr(HcmWorker,name),true);

           queryBuildDataSource = query.addDataSource(tableNum(HcmWorker));

           sysTableLookup.parmQuery(query);

           sysTableLookup.performFormLookup();

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: How to get Employee name in my field by selecting lookup with employee Name and employee Id

    Hi Ganesh,

    I understood that and hence was suggesting a change in design. Is this a field in a table for which you are creating the lookup?

  • Ganesh Potnuru Profile Picture
    Ganesh Potnuru 170 on at
    RE: How to get Employee name in my field by selecting lookup with employee Name and employee Id

    Hi Gunjan Bhattachayya

    I'm able to get that lookup with "Personnel Number" and "Worker Name" but while selecting personnel number is displaying in my custom field and I have tried the method you have suggested foreign key relation by using that I'm getting lookup but no value is displaying in my custom field after selection.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: How to get Employee name in my field by selecting lookup with employee Name and employee Id

    Hi Ax Trainee,

    What version are you using - AX 2012 or D365 F&O?

    When you create the field for worker, you can create an FK relation with HcmWorker which will store the RecId from HcmWorker table in the field. This will ensure that you get the default worker lookup On the form, this field will appear as a Reference group and you could then set the replacement field group pro.perty to "AutoIdentification".

    A good example is to look at  SalesTable\WorkerSalesResposible field. You can check the relations on this field and how it has been used in SalesTable form so that the worker name is displayed, based on user selection.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,986 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans