Microsoft Dynamics AX filtering data based on a ComboBox

user2711111 picture user2711111 · Aug 23, 2013 · Viewed 7.1k times · Source

I got a functionality to implement:

In PurchTable form in am told to create a combox on top of form which used enum as in purchTable.purchstatus field ie:invoiced,openorder,reveived,.

Now on clicking on any one of the above element in combo box i should only get that data in the grid below ie;if i click on invoiced ,record with purch status 'invoiced' will be show.

for this i created a combobox and used overidden method "selectionchange" code of selectionchange():

public int selectionChange()
{
    int ret;

 ret = super();
if(combobox.selection()==status::invoiced)
   {
  ... what will i have to write here to add range"invoiced" in the datasource 

  }



   if(combobox.selection()==status::All)
  {
 .  .. what will i have to write here to add range"invoiced" in the datasource 

 }

  }

Answer

DAXaholic picture DAXaholic · Aug 24, 2013

You could use this code (tested in AX2009) for your selectionChange() handler. Note: On your ComboBox you should set the property EnumType to PurchStatus (see Screenshot) so that the enum's elements are automatically added as entries.

If you have any questions regarding this code don't hesitate to comment ...

public int selectionChange()
{
    int             ret;
    QueryBuildRange range;
    ;

    ret = super();
    range = SysQuery::findOrCreateRange(
        purchTable_DS.query().dataSourceTable(tablenum(PurchTable)),
        fieldnum(PurchTable, PurchStatus));
    range.value(queryValue(this.selection()));
    purchTable_DS.executeQuery();

    return ret;
}

enter image description here