Friday, November 1, 2013

How to use entry point security in x++ based on a record

I had one requirement where in Sales order form the records which are confirmed must not be allowed to edit for a user role. This can be resolved by two ways:


1. To check the current user role and making the edit button as false on a condition,override active method of datasource and code as below:

select role
        where role.Name == 'RoleName'
    join userRole
        where userRole.SecurityRole == role.RecId
            && userRole.User == curUserId();
    if(userRole && SalesTable.DocumentStatus == DocumentStatus::Confirmation)
    {
    editButtonAllow= false;
    }

2. To avoid hard coding the Roles, we can use an entry point and check users access to the entry point

we need to create a menu item with a privilege and duty assigned to a role, override active method of datasource and use the menu item as below:

SecurityRights      sr;
AccessRight         accessRight = AccessRight::View;
sr = SecurityRights::construct();

accessRight = sr.menuItemAccessRight(SecurableType::MenuItemAction,menuitemActionstr(MenuItemName));
if(accessRight == AccessRight::View && SalesTable.DocumentStatus == DocumentStatus::Confirmation)
{
    ButtonName.enabled(false);
}
 else
 {
    ButtonName.enabled(true);
  }

No comments:

Post a Comment