How to link multiple data sources between each other

For example we need to tie following datasources:
InventSum
    InventDim
        InventBatch

InventBatch unique key index consists of ItemId and InventbatchId, therefore we need to link Invnetbatch with both InventDim and InventSum. However, if you try to do it using addLink method:
qbdsInventBatch.clearDynalinks();
qbdsInventBatch.addLink(fieldnum(InventDim, inventBatchId), fieldNum(InventBatch, inventBatchId));
qbdsInventBatch.addLink(fieldnum(InventSum, ItemId), fieldNum(InventBatch, ItemId));
You will get the run-time error: " Invalid Field/Related field combination":

There are a few tricks how this can be resolved:

1. Create a view from InventSum and InventDim and use it as a single data source and then join InventBatch to it.
2. Start query from Inventbatch data source and then join to it InventSum and InventDim. However, considering the example above in most cases it will not be logical. But it might work in your case.
3. Use extended ranges. The solution will have the following look:
QueryBuildRange qbrItemId = SysQuery::findOrCreateRange(qbdsInventBatch, fieldNum(InventBatch, ItemId));
str itemIdRange = strFmt('(%1.%2=%3.%4)', qbdsInventBatch.name(), fieldStr(InventBatch, ItemId), _inventSum_DS_Query.dataSourceName(formDataSourceStr(InventOnhandItem, InventSum)).name(), fieldStr(InventSum, ItemId));
qbrItemId.value(itemIdRange);

Additional query build extended range example

Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags