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
 

Sunday, October 27, 2013

Displaying an image on a form grid in Dynamics AX

Sometimes it is useful to display an image in  a data grid on a from to highlight certain records e.g. records with validation errors as in the example below:
















To achieve this requires 2 main steps:

1. Adding a display method on the table/form datasource that returns an ImageRes
 //BP Deviation Documented  
 display ImageRes errorExist()  
 {  
   #resAppl;  
   return this.ErrorLogged ? #ImageError : #ImageBlank2;  
 }  

2. Adding a new field control on the form by right-clicking on the Grid control within the form design and selecting New Control > Window




 

Set the properties of the new control as follows: