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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to set the relation of data source using query?

(0) ShareShare
ReportReport
Posted on by 139

Hello, 

I have 2 tables, salesTable and custPackingSlipTrans. 

How do I set the relation of datasource to the relation salesTable.salesId == CustPackingSlipTrans.OrigSalesId?

I tried the ff code below but it does not get the relations I need. 

query = new Query();
qbds = query.addDataSource(tableNum(SalesTable));

qbds = qbds.addDataSource(tableNum(CustPackingSlipTrans));
qbds.relations(true);

 info(query.dataSourceNo(1).toString());

This returns the query as 

"SELECT * FROM SalesTable JOIN * FROM CustPackingSlipTrans ON SalesTable.SalesId = CustPackingSlipTrans.SalesId"

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,926 Most Valuable Professional on at

    You can use addLink() to specify fields in code:

    Query query = new Query();
    QueryBuildDataSource salesTableDs = query.addDataSource(tableNum(SalesTable));
    QueryBuildDataSource transDs = salesTableDs.addDataSource(tableNum(CustPackingSlipTrans));
    
    transDs.addLink(fieldNum(SalesTable, SalesId), fieldNum(CustPackingSlipTrans, OrigSalesId));

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans