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

Add lookup method to form datasource with multiple tables and use GroupBy

(0) ShareShare
ReportReport
Posted on by 465

Hi,

I have a form that has Table 1 as a data source, Table 1 contains these fields  (custAccount,LId,LSId) (the three of them together should be unique)

Table1 Example

custAccount LId LSId

1                   1      1

1                   1       2
1                   2       1

Table1 has a relation with table Table 3 based on LId and LSId

Table 3  Example

LId LSId

1     1

1     2

2     1

3     2

and Table 3 has relation with Table2 based on LId

Table2 Example

LId         Name

1            first

2           second

3          third

 

Now in the form i want to add Lids to a specific customer. but Lid lookup is showing me Lid and LSId where Lid is repeating because there are more than one LSId for each LId

So i want to change the lookup to contain only LId and Name  (where LId is not repeated in lookup) but the code below is not working

SysTableLookup          sysTableLookup  = SysTableLookup::newParameters(tableNum(Table1),_formControl);
Query                   query           = new Query();
QueryBuildDataSource    qbds            = query.addDataSource(tableNum(Table1));
QueryBuildDataSource    qbdsJoin        = qbds.addDataSource(tableNum(Table2));

qbdsJoin.joinMode(JoinMode::InnerJoin);
qbdsJoin.relations(false);
qbdsJoin.addLink(fieldNum(Table1, LId), fieldNum(Table2, LId));
qbds.orderMode(OrderMode::GroupBy);
qbds.addGroupByField(fieldNum(Table1,LId));
sysTableLookup.addLookupField(fieldNum(Table1, LId));
sysTableLookup.addLookupField(fieldNum(Table2, LName));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

  • Martin Dráb Profile Picture
    232,011 Most Valuable Professional on at
    RE: Add lookup method to form datasource with multiple tables and use GroupBy

    An alternative solution is creating a view with those two tables and using this view as the source of data for the lookup.

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Add lookup method to form datasource with multiple tables and use GroupBy

    kashperuk.blogspot.com/.../sysmultitableloookup-dynamic-lookups.html

  • D365FO user Profile Picture
    465 on at
    RE: Add lookup method to form datasource with multiple tables and use GroupBy

    Hi Ergun,

    How to add manually? Can you explain what do you mean please

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Add lookup method to form datasource with multiple tables and use GroupBy

    You are using values from two table (lookupField) so you need use SysMultiTableLookup

    its not system class so you need add manualy

    or you can use a view or a tmp table

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans