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

No comments:

Post a Comment