Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
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,421 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,421 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans