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
4 thoughts on “AX2012 : Use queries as criteria”
Thanks for you post which helped me understand about the Criteria.
I have small issue which i am facing with multiple days
Here i am storing the range of criteria in Container Field in one form
when i am trying the retrieve that range in another form using that table(TestTable)
i am getting error at this point
querybuilddatasource = new Query(TestTable.ContainerField);
I am getting error as Bad Container, if you have any idea regarding this please help me.
Microsoft Dynamics AX is an adaptable business management solution that enables companies and their workers to make business decisions with greater confidence.
Please share on :- Dynamics ax consulting
Pingback: Master data synchronization using ColumbusSync - Warehouse Management and Distribution - Microsoft Dynamics AX - Microsoft Dynamics Community
Pingback: Master data synchronization using ColumbusSync | Kurt Hatlevik – Dynamics Ax Blog