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);
       dateInMonth=tmpDate;
       firstDateOfMonth = DateStartMth(dateInMonth);
       dateInMonth=tmpDate;
       endDateOfMonth= endmth(dateInMonth);
        ds.addRange(fieldNum(ERAWriteOffCalculation, calcdate)).value(queryRange(firstDateOfMonth, endDateOfMonth));

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

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