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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Multi table custom lookup

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

I need your help, I will need to create custom lookup - Contact person id and Name.

I am able to create "Contact person id" lookup but  for "Name" field we need another table "DirPartyTable".

How we use two table for creating lookup?

I gone through some blog, they have mentioned "SysMultiTableLookup" but I am not able to get it "SysMultiTableLookup" class.

Can you please suggest clue.

query = new Query();
contactPersonQBDS = query.addDataSource(tableNum(ContactPerson));
contactPersonQBDS.addRange(fieldNum(ContactPerson, ContactForParty)).value(strFmt("%1",vendTable.Party));

QbdsDirPartyTable = contactPersonQBDS.addDataSource(tablenum(DirPartyTable));

--QbdsDirPartyTable.joinMode(JoinMode::InnerJoin);
--QbdsDirPartyTable.relations(true);
--QbdsDirPartyTable.addLink(fieldNum(ContactPerson,party), fieldNum(DirPartyTable, RecId));

sysTableLookup = SysTableLookup::newParameters(tableNum(ContactPerson), sender);
sysTableLookup.addLookupField(fieldNum(ContactPerson, ContactPersonId));
--sysTableLookup.addLookupField(fieldNum(ContactPerson, Name));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

I have the same question (0)
  • Adria Ariste Profile Picture
    User Group Leader on at

    If you want to add a field from another table to the lookup just change sysTableLookup.addLookupField(fieldNum(ContactPerson, Name)); to sysTableLookup.addLookupField(fieldNum(DirPartyTable, Name)); which is the field you need. The rest of your code should be fine (are you using -- to comment the code? In X++ we use // for single line and /* */ for multiline comments)

    Regards,

    Adrià Ariste - Senior technical consultant @ Axazure - Read my blog!

  • Community Member Profile Picture
    on at

    Thanks Adrià.

    I tried with below code but second field in lookup (that is Name) display null value:

    query = new Query();
    contactPersonQBDS = query.addDataSource(tableNum(ContactPerson));
    contactPersonQBDS.addRange(fieldNum(ContactPerson, ContactForParty)).value(strFmt("%1",vendTable.Party));

    QbdsDirPartyTable = contactPersonQBDS.addDataSource(tablenum(DirPartyTable));

    QbdsDirPartyTable.joinMode(JoinMode::InnerJoin);
    QbdsDirPartyTable.relations(true);
    QbdsDirPartyTable.addLink(fieldNum(ContactPerson,party), fieldNum(DirPartyTable, RecId));

    sysTableLookup = SysTableLookup::newParameters(tableNum(ContactPerson), sender);
    sysTableLookup.addLookupField(fieldNum(ContactPerson, ContactPersonId));
    sysTableLookup.addLookupField(fieldNum(DirPartyTable, Name));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

    pastedimage1570927890455v1.png

  • Suggested answer
    Martin Dráb Profile Picture
    237,980 Most Valuable Professional on at

    The answer above is wrong - sysTableLookup.addLookupField(fieldNum(DirPartyTable, Name)) will select a field from ContactPerson table which has the same ID as Name field has in DirPartyTable, which doesn't make a good sense.

    The easiest way may be using a display method - take a look where ContantPerson already doesn't have one. Then you'd use addLookupMethod() instead of addLookField().

    SysMultiTableLoookup isn't a standard class. You can get it here.

    Yet another solution is building a view and using the view with all fields you need and then using this view in your lookup, as if all fields were in a single table.

  • Community Member Profile Picture
    on at

    Have you a problem solved?

    If not then I have a solution

    Step -1: Create a query then create a view

    Step - 2: If there is a reference control then you need to create a form lookup then add some piece of code

    Reply to me then I have a code to use for multi-table customer lookup.

  • ANPavel Profile Picture
    5 on at

    Hello, can you help me with the solution using a view in lookup? I belive this is the only solution in d365 for multiple table lookup. Thank you.

  • Martin Dráb Profile Picture
    237,980 Most Valuable Professional on at

    ANPavel, we can't help you unless you explain your problem.

    Also, you're wrong in thinking that the other two solutions can't be used in F&O. Display methods works the same as before (at least since Axapta 3.0) and SysMultiTableLoookup can be used too, you just need to install a version for F&O (e.g. from here).

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans