user2711111
user2711111

Reputation: 1

Microsoft Dynamics AX filtering data based on a ComboBox

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 

 }

  }

Upvotes: -1

Views: 8065

Answers (2)

j.a.estevan
j.a.estevan

Reputation: 3097

Imagine you have a Form with a DataSource called JAEEMantenimiento that you want to filter from the field Tipo, and a data-unbound combobox called FiltroTipo. This is the code you need to filter when combo changes selection:

// classDeclaration of the FORMULARIO!!
public class FormRun extends ObjectRun
{
    QueryBuildRange     qbrTipo;
}

// Form DATASOURCE (JAEEMantenimiento)
public void init()
{
    super();

    qbrTipo = JAEEMantenimiento_DS.queryBuildDataSource()
                    .addRange(fieldNum(JAEEMantenimiento, Tipo));
}

// Form DATASOURCE (JAEEMantenimiento)
public void executeQuery()
{
    qbrTipo.value(queryValue(FiltroTipo.selection()));

    super();
}

// COMBOBOX (FiltroTipo)
public boolean modified()
{
    boolean ret;

    ret = super();

    JAEEMantenimiento_DS.executeQuery();

    return ret;
}

This is AX 2012 code, but it should work just fine in 2009.

Upvotes: 1

DAXaholic
DAXaholic

Reputation: 35368

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

Upvotes: 4

Related Questions