In Dynamics AX 2012 the relation between different records is often defined as a “table-group-all” relation. One example of this is the setup of supplementary items, where you can define the relation as a Table-Group-All relation.
Even though this approach is easy to use and understand, it does have limitations. Often you would like to pin-point the relationships even further. It can be based on other fields in the source record.
I wanted to look against another approach, where I can use a query as a criteria. Normally queries are used to fetch specific records based on a set of ranges and defined sorting criteria.
I have a label software, that integrates Dynamics AX 2012 with BarTender, and it is generic, meaning that it can produce labels based on all data sources in AX.
So in this case, I can setup that when the user wants to print a label, I can search through a set of label templates, and check this record if it fits the query criteria. I then have a endless possibility to specify all kinds of criteria to select the best matching label template.
The trick is to add the source recid as a range to the packed query criteria exactly when checking for it. Also to add the “firstonly” hint, so that you don’t query for more than you want.
Here is some sample job, I used to test out this approach:
Microsoft is also using the same approach when selecting is a WMSorder can be added to a existing shipment. Take a look at WMSShipment.canWMSOrderBeAdded() or at wmsShipmentTemplate.canWMSOrderBeAdded(), then you see the same pattern.
I hope you see the value in this, and that it can open a complete new way of adding rules and relational information to Dynamics AX 2012. With this approach we can generically pinpoint our criteria for our rules.
Take care and happy DAXing