Tuesday, November 22, 2016

AX 2012 - How to Add Linked Datasource using parent Datasource fields

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.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!