AX – D365FO – Clear a value of a previously query set filter

If you have done a query in a form and you you want to clean previouslu query filter you have to follo w this code

public void executeQuery()


   // Get the filter value from the filter control.

   date firstYearOfMonth;
   str monthStr;
   str yearStr;
   MonthsOfYear monthEnum;
   int monthEnumToInt;
   TransDate tmpDate;
   TransDate dateInMonth;
   TransDate firstDateOfMonth;
   TransDate endDateOfMonth;
   QueryBuildDataSource ds;
   monthStr = MonthsList.valueStr();
   yearStr = YearsList.valueStr();
   ds = this.query().dataSourceTable(tablenum(ERAWriteOffCalculation));

   if (yearStr != "")
       monthEnum = str2enum(monthEnum,monthStr);
       monthEnumToInt = enum2int(monthEnum);
       tmpDate = str2Date("15/" + int2str(monthEnumToInt) + "/" + yearStr, 123);
       firstDateOfMonth = DateStartMth(dateInMonth);
       endDateOfMonth= endmth(dateInMonth);
        ds.addRange(fieldNum(ERAWriteOffCalculation, calcdate)).value(queryRange(firstDateOfMonth, endDateOfMonth));

       ds.clearRange(fieldNum(ERAWriteOffCalculation,calcdate)); //This code cear previously set filters

Leave a Reply

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

You are commenting using your 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