Tuesday, September 17, 2019

Add a pop up query filter to any form

I have always had to look for code to add query filter to any form, and finally I am writing this to make sure it is easily available for me next time

In the Form->(Parent) DataSource->init method initialise the qbds with required ranges.

public void init()
{
    QueryBuildDataSource qbds;

    super();

    qbds = this.query().dataSourceTable(tableNum(ParentTable));

    qbds.addRange(fieldNum(ParentTable,ItemId));
    qbds.addRange(fieldNum(ParentTable,ProductGroupId));        
}

And in the Form->Run method, call it using the SysQueryRun

public void run()
{
    SysQueryRun queryRunCriteria;

    if ( !this.args().dataset() )   // If there is a data set, we assume there will be a dynalink.
    {
        queryRunCriteria = new SysQueryRun(ParentTable_ds.query());
        queryRunCriteria.promptAllowAddDataSource(false);

        if ( queryRunCriteria.prompt() )
        {
            ParentTable_ds.query(queryRunCriteria.query());
            super();
        }
    }
    else
        super();
}

https://1drv.ms/b/s!AqnsuiFEumq1kDzuc8oGKQBxwLOL?e=Vyf7fZ

Monday, March 25, 2019

Important references

Best simple sys operation controller tutorial https://stoneridgesoftware.com/batch-processing-in-dynamics-ax-2012-using-sysoperation-framework/

Business runtime functions https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-ref/xpp-business-run-time-functions

Refresh AX Table recid sequence - https://stoneridgesoftware.com/microsoft-dynamics-ax-error-the-record-already-exists/

WHERE vs ON links in Dynamics AX - https://docs.microsoft.com/en-us/dynamicsax-2012/developer/how-to-use-the-queryfilter-class-with-outer-joins


Multiple lines for multiple headers - http://dev.goshoom.net/en/2013/11/lines-for-multiple-headers/

Change from iisexpress to iss - https://community.dynamics.com/blogs/post/?postid=4f987f63-3193-424f-b415-0c8253e026ff

Query tips: These are a few things I have found during my testing. If people see different results for these in their testing, please comment and I will update it.

1) Exists vs Inner Join - If the number of records on the parent table are over 1000, always use exist join when parent table is bigger than child table, but use inner join when child table is bigger than parent, as it ends up using the seek operation on the whole child table after cross product for exist join, but uses index when using Inner Join.

2) Always use the smallest table as the parent table when writing a query as that will make sure the join operations are performed based on the smallest (in terms of number of records) table in mind reducing the cross product to the smallest quantity.


Saturday, March 16, 2019

AX 2012 add new checkbox in SRSPrintDestinationTokens

1) Find the token type that needs modifying, for example, in my case, it was print mgmt token type, so all the form objects are defined in PrintMgmtPrintDestinationTokens.

2) Add the type of form control in the class declaration