A blog offering various X++ code snippets and tips for Microsoft Dynamics AX

Tuesday, October 28, 2008

Dynamics Ax User Ranges

I recently received the following development question regarding Dyanmics Ax:

How to access the user specified ranges in a form i.e. the ranges set manually by the use, using right click 'Filter by field / Filter by selection' or using the advanced query button.

This is actually quite simple as shown in the following code:


public void executeQuery()
{
  Query query;
  int i;
  ;
  super();

  // get a pointer to the current query
  query = this.queryRun().query();

  // Traverse the ranges for the specified table in the query
  for (i = 1; i <= query.dataSourceTable(tableNum(custTable)).rangeCount(); i++)
  {
    // For each range field found display the field name and value chosen by user
    info(strfmt("Field Name: %1 ", fieldid2name(tableNum (CustTable), query.dataSourceTable(tableNum(custTable)).range(i).field())));
    info(strfmt("Value chosen by user: %1", query.dataSourceTable(tableNum(custTable)).range(i).value()));

// Or perform any other work
  }
}


The above code was written in the executeQuery() method of the DataSource to show the field names and values chosen by the user every time he makes a selection.

Tested on Ax 4.0 and 2009

If you any questions or comments e-mail me on: mirko@mirkobonello.com

No comments: