Wednesday, November 6, 2013

Display required license on Secuirty privileges form in AX2012

To assist with creating security roles for lower license levels (Functional, Self-serve, etc) I made a small mod to the Security prviledges form to display the license level required for each permission object. Easier than having to generate and run the license report everytime you make a change or having to lookup each permission in the AOT to see the license level.









These fields can be added by creating two new display methods on the securableObject data source on the SysSecTasksEditPS form:


 public display UserLicenseType displayViewUserAccessLicense(SecurableObject _object)  
 {  
   #AOT  
   #Properties  
   #define.PropertyReadUserLicense('ViewUserLicense')  
   #define.PropertyFullAccessUserLicense('MaintainUserLicense')  
   UserLicenseType userLicType;  
   TreeNode    treeNode;  
   EntryPointType type = Global::enum2int(_object.Type);  
   str       nodePath =  
             (type == EntryPointType::MenuItemDisplay) ? strFmt('%1\\%2', #MenuItemsDisplayPath, _object.Name) :  
             (type == EntryPointType::MenuItemOutput) ? strFmt('%1\\%2', #MenuItemsOutputPath, _object.Name) :  
             (type == EntryPointType::MenuItemAction) ? strFmt('%1\\%2', #MenuItemsActionPath, _object.Name) :  
             (type == EntryPointType::WebUrlItem) ? strFmt('%1\\%2', #WebMenuItemsUrlPath, _object.Name) :  
             (type == EntryPointType::WebActionItem) ? strFmt('%1\\%2', #WebMenuItemsActionPath, _object.Name) :  
             (type == EntryPointType::WebManagedContent) ? strFmt('%1\\%2', #WebContentItemsManagedPath, _object.Name) :  
             '';  
   Map typeSet = new Map(Types::String, Types::Enum);  
   // Available types property values  
   typeSet.insert('', UserLicenseType::None);  
   typeSet.insert('None', UserLicenseType::None);  
   typeSet.insert('SelfServe', UserLicenseType::SelfServe);  
   typeSet.insert('Task', UserLicenseType::Task);  
   typeSet.insert('Functional', UserLicenseType::Functional);  
   typeSet.insert('Enterprise', UserLicenseType::Enterprise);  
   typeSet.insert('Server', UserLicenseType::Server);  
   if (nodePath != '')  
   {  
     treeNode = TreeNode::findNode(nodePath);  
   }  
   if (treeNode)  
   {  
     userLicType = typeSet.lookup(treeNode.AOTgetProperty(#PropertyReadUserLicense));  
     treeNode.treeNodeRelease();  
   }  
   return userLicType;  
 }  

The above code adds a display method to display the ViewUserAccessLincense. The other display method is exactly the same except #PropertyFullUserLicense is used instead of  #PropertyReadUserLicense on the following line:

userLicType = typeSet.lookup(treeNode.AOTgetProperty(#PropertyReadUserLicense));

Then all you need to do is add the display methods to the grid in the form design and you're done
 

1 comment:

  1. Hi this is very interesting and helpfull. I know that it's maybe not the right place to ask for help but I really need some.
    I'm using Dynamics Ax 2012 R2 and I have some of new roles created and other modified ( added or removed duties and privileges ) and now I need a report(table) about my roles which contains the following columns:
    Role Name; Role AOT Name; Duty Name; Duty AOT Name; Privilege Name; Privilege AOT Name; Menu Item Name; License CAL;
    I've searched the net and the forums and I've found very similar scripts and codes which give Role Names with License Types or Entry Point With Licenses but I couldn't find some that suits my task.
    I have Security Development Tool and tried to sort this out manually, but after one role with more than 1000 privileges associated with it, it was clear that that cannot be done by hand :).
    I have tried to write some code using SysSecRoleEntryPointsTmp and SysUserLicenseMetadataTmp but with no luck. I couldn't manage to get all the fields in the report I need.
    So if someone can help me or give me some clue it will very helpfull for me and I'll value it a lot. Thanks in advance.

    ReplyDelete