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

1 comment:

microsoft dynamics said...

Hello! Thank you a lot for showing the way of how to Add Linked Datasource using parent Datasource fields in Microsoft Dynamics AX solution.
It's exactly what I needed, thank you for sharing :)