Sunday 27 May 2012

Adding a range in Data Set in AX 2009

Hi friends,

Today we are going to add range in a Dataset.

A data set, typically used to access data for Enterprise Portal, can have one or more data sources from which data is accessed. You can use X++ code to add a range that restricts the data that is accessed by the data source. The code that adds the range must be written correctly so that only the data in the range is accessed.

Adding a Range:

To add a range for the data source that is used by a data set, you must override the init method for the data source. In this method, create a QueryBuildRange object that defines the range and specifies the values allowed. To prevent the range from being changed or removed, set the range status to hidden. This last step is very important to prevent data outside the range from being accessed.

The following example sets a range for the ContactPerson data source in the EPCustTableInfo data set. The range prevents rows from being accessed that have empty values in the ContactPerson or CustAccount fields. The status of the range is set to hidden to make sure that the range cannot be changed or deleted.

public void init()
{
QueryBuildRange rangeCustAccount;
super();

rangeCustAccount = this.query().dataSourceTable(tablenum(ContactPerson)).addRange(fieldnum(ContactPerson, CustAccount));
rangeCustAccount.value(SysQuery::valueNotEmptyString());
rangeCustAccount.status(RangeStatus::Hidden);
}





Vivek Chirumamilla

No comments:

Post a Comment