Announcements
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
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.
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
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.
Yes I was wrong there as there is no relation between these two tables. How can I do this now ?
Regards
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.
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
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.
André Arnaud de Cal...
294,095
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator