Disabling XDS security on demand

When using XDS it is very simple to apply security policy to whole application based on role assigned to user. To do that ContextType in security policy needs to be set to RoleName and role must be selected as well. With this configuration there is no need to add any changes to the code, XDS will work everywhere for user with this particular role.

However, sometimes it is required to disable XDS. For example, let’s imagine that there is a form with grid and records visible in it. Some of them are not visible because of XDS restriction. On the same form there is a button called Detect errors which traverse through all records and makes some validations. Normally not every record would be validated but it’s possible to temporarily disable XDS so that system will find all records.

Below is the solution with simple code disabling and afterwards enabling XDS security. 

for AX 2012

XDSServices  xdsServices = new XDSServices();
;

xdsServices.setXDSState(0);

// code placed here will not be restricted by XDS

xdsServices.setXDSState(1);
For D365
 I want to disable the security policy for some forms. It is better to disable security policy when user clicks on the menu item. Otherwise we should consider all lookup and fields which I think it is not a good approach. i.e. We should use uncheck::XDS in every method required. One solution is linking each display menu item to action menu item. In the main method of the action menu item we disable the security policy then run the related display menu item.
Now we need to wrap code where we want to disable XDS policy with unchecked(Uncheck::XDS)
1
2
3
4
5
unchecked(Uncheck::XDS)
{
    // user custom code place here
}

Comments