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

Announcements

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();

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    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

  • D365FO user Profile Picture
    465 on at

    Hi Ergun,

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

  • ergun sahin Profile Picture
    8,826 Moderator on at
  • Martin Dráb Profile Picture
    238,605 Most Valuable Professional on at

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

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 662 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 280 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 201 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans