AX 2012 - How to Add Linked Datasource using parent Datasource fields
Views (1099)
Hi Guys
Can happen to add Datasource to a query using fields related to other parent Datasource.
In order to achieve this goal, the trick is use the third parameter of the AddLink Kernel Method of the QueryBuildDataSource class, like this:
qbdsXX = SysQuery::FindOrCreateDataSource(DataSource_ds.query(), tableNum(TableChild), tableNum(TableParent) );
qbdsXX.relations(false);
qbdsXX.joinMode(JoinMode::InnerJoin);
qbdsXX.fetchMode(QueryFetchMode::One2Many);
qbdsXX.addLink(fieldNum(TableParent, FieldA), fieldNum(TableChild, FieldA));
qbdsXX.addLink(fieldNum(TableParent, FieldB), fieldNum(TableChild, FieldB));
qbdsXX.addLink(fieldNum(TableParentParent, FieldC), fieldNum(TableChild, FieldC), DataSourceParent );
Stay tuned!
This was originally posted here.

Like
Report
*This post is locked for comments