Sunday 8 July 2012

Filter the DataSource with a condition and force the user to see his own data

In this Post i will demonstrates how filter a data regarding to the user who logged into Ax, in this example      i will filter only the data of the user related to his department.

First override the method execute query in the DataSource then type your code as the example below.


public void executeQuery()
{


// This is the table which include the matching between the user and the department 
 AssetExtensions_User_Department_SETUP myAssetExtensions_User_Department_SETUP;

// Get the department id of the user 
select DepartmentID from myAssetExtensions_User_Department_SETUP where myAssetExtensions_User_Department_SETUP.UserID == curUserId() ;


// Filter the data source

    myQueryBuildRange = this.query().dataSourceName('AssetComponentsTable').addRange(fieldnum(AssetComponentsTable,OwnerDepartmentID));
    myQueryBuildRange.value(myAssetExtensions_User_Department_SETUP.DepartmentID);


// Block the filter or do not allow the user to filter by any other departments
myQueryBuildRange.status(RangeStatus::Hidden);

    super();

}

No comments:

Post a Comment