Skip to main content

Notifications

Community site session details

Community site session details

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

How to create custom lookup from multiple tables

(0) ShareShare
ReportReport
Posted on by 86

Hi Experts,

I have to create a lookup in a form in which to fields are coming from purchtable and two fields are coming from banklc table. Kindly PFA code and please help hpw to do this.

/// 
/// 
/// 
/// 
/// 
[FormControlEventHandler(formControlStr(LedgerJournalTransVendInvoice, LedgerJournalTrans_LCDocumentNumber), FormControlEventType::Lookup)]
public static void LedgerJournalTrans_LCDocumentNumber_OnLookup(FormControl sender, FormControlEventArgs e)
{      
    Query                   query = new Query();
    QueryBuildDataSource    qbds;
    QueryBuildDataSource    qbdsJoin;
    SysTableLookup          sysTableLookup = sysTableLookup::newParameters( tableNum(PurchTable), this);
    ;
 
    qbds= query.addDataSource( tableNum(PurchTable));
    qbdsJoin= qbds.addDataSource( tableNum(BankLC));
    qbdsJoin.relations( false);
    qbdsJoin.fields().dynamic(NoYes::Yes);
    qbdsJoin.addLink( fieldNum(PurchTable, PurchId), fieldNum(BankLC, PurchTable));
    qbdsJoin.joinMode(JoinMode::OuterJoin);
 
    sysTableLookup.parmQuery(query);
    sysTableLookup.addLookupfield( fieldNum(PurchTable, PurchId), true);
    sysTableLookup.addLookupfield( fieldNum(PurchTable, BankDocumentType), true);
    sysTableLookup.addLookupfield( fieldNum(BankLC, BankLCNumber));
    sysTableLookup.addLookupfield( fieldNum(BankLC, BankAccountId));
    QueryBuildDataSource = query.addDataSource(tableNum(PurchTable));
    QueryBuildDataSource = query.addDataSource(tableNum(BankLC));
    sysTableLookup.performFormLookup();
}

Regards

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: How to create custom lookup from multiple tables

    Add that query to view - Now in the view - Add the fields you want from the view DataSource. Refer to the below Microsoft documentation.

    https://learn.microsoft.com/en-us/dynamicsax-2012/developer/how-to-create-a-view-based-on-a-query

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to create custom lookup from multiple tables

    I have created the query now what to do please tell. I have used purch table as parent and banklcimport as child and relation between them is purchtable.purchid == banklcimport.purchtable.

    regards

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: How to create custom lookup from multiple tables

    BankLC and BankLCImportLine tables are inherited table. BankLCImportLine  table has relation with PurchTable.

    So, you can add PurchTable and BankLCImportLine in the view.

    Since BankLC and BankLCImportLine are inherited you can access BankLC fields in the BankLCImportLine table itself.

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to create custom lookup from multiple tables

    Yes I was wrong there as there is no relation between these two tables. How can I do this now ?

    Regards

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: How to create custom lookup from multiple tables in d365fo

    But you have mentioned the relation between the two tables in the query.

    qbdsJoin.addLink( fieldNum(PurchTable, PurchId), fieldNum(BankLC, PurchTable));

    Parent table will be PurchTable - Inside the DataSource of the PurchTable, add BankLC table with relations.

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to create custom lookup from multiple tables in d365fo

    Hi Girish,

    There is no relation between these two tables and in the view which table will be parent table? can you please clear this?

    Regards

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: How to create custom lookup from multiple tables in d365fo

    Hi ax.tech,

    To make it simple you can create a view - View contains PurchTable and BankLC as a DataSource with relations.

    So that you can use that view in the lookup query instead of joining PurchTable and BankLC.

    Thanks,

    Girish S.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans