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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to use 'Distinct' on a field in Query for Look up

(0) ShareShare
ReportReport
Posted on by
Customer Product Product Reference
Cust1 P1
Cust1 P2
Cust1 P3
Cust2 P4
Cust2 P5
Cust2 P6
Cust3 P7
Cust3 P8
Cust3 P1

I have a non datasource field, 'Customer' on a form, which is displaying all the customer records through the following lookup() method. But I want to display distinct customers rather than displaying all the customer entries(for ex:  from the above table, it is displaying the Cust1 3 times, Cust2 3 times etc.) like Cust1, Cust2, Cust3 etc). Where and how do I add 'Distinct' condition on 'Customer'field in the table.

public void lookup()

{

QueryBuildDataSource qdbs;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustProductRelationTable), this);
Query query = new Query();

qdbs = query.addDataSource(tableNum(CustProductRelationTable));

qdbs.addRange(fieldNum(CustProductRelationTable, EndDate)).value(queryValue(dateNull()));

sysTableLookup.addLookupfield(fieldNum(CustProductRelationTable, AccountNum));

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You need to group by on the field:

    geekswithblogs.net/.../group-by-on-a-look-up-query.aspx

  • Community Member Profile Picture
    on at

    Thank you for the help. I am able to fix it now.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans