AX – D365FO – Add dropdown filters that show results into a form grid but disconnected from the form datasource.

This is the result we want to obtain, 2 dropdown filters that show results into a form grid but disconnected from the form datasource.

When the year is selected and month no then the form will show data from 01/01/year and 31/12/year.

When the year and month are both selected then the form will show data from first day of the month of the uar and the last day of the selected year

Go to Form, Design, Grid container.

Add new Combobox control

Set Enum property to “MonthOfYear” enum

Now add a new IntEdit Control to add the extended data type (The EDT is custom and linke to a a custom table containing a list of years. to see how to create the relation see article : https://d365ffo.com/2021/07/13/ax-d365fo-add-table-relation-to-an-extended-data-type-edt

Raname the 2 controls

This is the result we have obtained

Put this code inside both modified methods

public boolean modified()

{

   boolean ret;

   ret = super();

   // A new filter value has been selected; refresh the form using that filter value.

   ERAWriteOffCalculation_ds.executeQuery();

   return ret;

}

Put this code inside executeQuery of datasource

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));

   ds.clearRange(fieldNum(ERAWriteOffCalculation,calcdate));

 

   if (yearStr != "")

   {

 

       if (monthStr != "")

       {

           monthEnum = str2enum(monthEnum,monthStr);

           monthEnumToInt = enum2int(monthEnum);

 

           tmpDate = str2Date("15/" + int2str(monthEnumToInt) + "/" + yearStr, 123);

 

 

           dateInMonth=tmpDate;

 

           firstDateOfMonth = DateStartMth(dateInMonth);

           dateInMonth=tmpDate;

           endDateOfMonth= endmth(dateInMonth);

       }

       else

       {

           firstDateOfMonth = str2Date("01/01/" + yearStr, 123);

           endDateOfMonth =  str2Date("31/12/" + yearStr, 123);

       }

 

 

       ds.addRange(fieldNum(ERAWriteOffCalculation, calcdate)).value(queryRange(firstDateOfMonth, endDateOfMonth));

   }

   /*else

   {

       ds.clearRange(fieldNum(ERAWriteOffCalculation,calcdate));

   }*/

 

 

 

   super();

}

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...