Monday, 10 March 2014

how to enable or disable security policy through code.

http://daxdilip.blogspot.in/2013/03/issue-with-security-policy-in-dynamics.html

 have found a workaround, by taking a different approach to the scenario and instead of attaching the Security Policy to the Role directly, I changed the ContextType to “ContextString” from the previously defined “Rolename” and put a ContextString called “DNTestSec”.
(Step 1)


I then attached this ContextString to the role and query. (Please see below Step 2 and Step 3)

After making this changes, the below code makes sense, as it can enable/disable security at run-time because it can find the ContextSecurity string. (Below is a standard ax code which you can find in one of the DirParty* forms in AOT)


{
    #DirParty
    XDSServices xds = new XDSServices();

 // Trigger the Dirparty table XDS  policies by passing the context string 
   xds.setXDSContext(0, #RestrictParty);
  super();

 // Disable the Dirparty XDS policy by passing a blank context string .

   xds.setXDSContext(0, ' ');
}

No comments:

Post a Comment