AX – D365FO – Clear data source query ranges

If you add a query range with a certain value to a Query, then next time you execute the query with another value the query doesn’t clear previous range.

In order to clean the old values you have to use clearRanges() method

see example below

        /// </summary>
public void executeQuery()
        {
            super();
            QueryBuildDataSource productCategory_ds = this.query().dataSourceTable(tableNum(Al0VendorSearchCriteria));
            this.query().dataSourceTable(tableNum(Al0VendorSearchCriteria)).clearRanges();

            int i = ActivityTree.getSelection();
            if(ActivityTree.getSelection() != 0)
            {
                int64 currentNodeSelected = ActivityTree.getItem(ActivityTree.getSelection()).data();
                if(currentNodeSelected != 0)
                {
                    productCategory_ds.addRange(FieldNum(Al0VendorSearchCriteria, VendorActivityRefRecId)).value(int642Str(currentNodeSelected));
                }
            }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s