Hello,
I survey all WWW about AX 2012, found the script in X++ can't work.
could have anyone had the code can share??
I found a script , but had a running error:
CommaTextIo object not initialised.
Stack trace
(C)\Jobs\AE_SecurityReport - line 95
line 95 is :commaTextIo.write('RoleName,AOTRoleName,Label,Description,MenuItemType,MenutItemName,MenuItemel,Duty,Privilege,Access Level');
could anyone can fix it??
Thanks in advance.
The script is:
from the webside: anithasantosh.wordpress.com/.../extract-security-objects-details-for-a-role
public void AE_SecurityReport()
{
#AOT
#File
SecurityRoleAOTName roleAOTName ;
SecurityRoleName roleName;
SecurityRole securityRole;
TreeNode treeNode;
TreeNode treeNodeDuty = infolog.findNode(@'\Security\Duties\');
TreeNode treeNodePriv = infolog.findNode(@'\Security\Privileges\');
TreeNode treeNodePrivNew;
TreeNode treeNodeDutyNew;
TreeNode treeNodeObj;
TreeNodeTraverser treenodeT;
TreeNode treeNodeRole;
TreeNode treeMenu;
Set setDuty ;
Set setPrivilege;
Set setMenuItem;
SetEnumerator setEnumerator ;
SysModelElement modelElement;
SysModelElementType modelElementType;
UtilElementName name;
TreeNodePath path;
str maintainlicenseType;
str viewlicenseType;
str menuLabelName;
str roleAccess;
str configurationKey;
//str commaTextIo;
String50 menuName;
String255 securityPrivilege, securityDuty, securityMenuPath;
String50 engLabel, frLabel, engDescription, frDescription;
Label objLabel = new Label();
CommaTextIo commaTextIo;
FileIOPermission permission;
FileName fileName;
container getPrivilegeDetails(
SecurityRoleAOTName _roleName, MenuItemName _menuItemName)
{
SecurityTaskEntryPoint secTaskEntryPoint;
SecurityRole secRole;
SecurityRoleTaskGrant secRoleTaskGrant;
SecurityEntryPointLink secEntryPointLink;
SecurableObject secObject;
SecurityTask secTask,secTaskDuty;
SecuritySubTask secSubTask;
String255 secPrivilege, secDuty;
container conPrivDuty, conSecDuty ,conAccess ;
container conSecPrivilege;
Select secRole where secRole.AotName == _roleName;
select secObject where secObject.Name == _menuItemName &&
(secObject.Type == SecurableType::MenuItemDisplay ||
secObject.Type == SecurableType::MenuItemAction ||
secObject.Type == SecurableType::MenuItemOutput);
select secEntryPointLink where secEntryPointLink.EntryPoint == secObject.RecId;
while select SecurityTask from secRoleTaskGrant
where secRoleTaskGrant.SecurityRole == secRole.RecId
join SecuritySubTask from secSubTask
where secSubTask.SecurityTask == secRoleTaskGrant.RecId
join AotName from secTask
where secTask.RecId == secSubTask.SecuritySubTask
&& secTask.Type == SecurityTaskType::Privilege
join AotName from secTaskDuty
where secTaskDuty.RecId == secSubTask.SecurityTask
&& secTaskDuty.Type == SecurityTaskType::Duty
join PermissionGroup from secTaskEntryPoint
where secTaskEntryPoint.EntryPoint == secEntryPointLink.RecId &&
secTaskEntryPoint.SecurityTask == secSubTask.SecuritySubTask
{
conSecPrivilege += secTask.AotName;
conSecDuty += secTaskDuty.AotName;
conAccess += enum2str(secTaskEntryPoint.PermissionGroup);
}
conPrivDuty = [conSecPrivilege, conSecDuty,conAccess];
return conPrivDuty;
}
;
permission = new FileIOPermission(fileName,#io_write);
permission.assert();
commaTextIo = new CommaTextIo(fileName,#io_write);
commaTextIo.write('RoleName,AOTRoleName,Label,Description,MenuItemType,MenutItemName,MenuItemel,Duty,Privilege,Access Level');
select Name,AotName from securityRole where securityRole.AotName == "Production Manager";
roleAOTName = securityRole.AotName;
treeNode = TreeNode::findNode(@'\Security\Roles\'+ roleAOTName).AOTfirstChild();
treeNodeRole = treeNode::findNode(@'\Security\Roles\'+ roleAOTName);
// Loop through the roles to get Duties
treenodeT = null;
setDuty = new Set(Types::String);
treenodeT = new TreeNodeTraverser(treeNode, false);
while(treenodeT.next())
{
setDuty.add(treenodeT.currentNode().AOTname());
}
setEnumerator = null;
setPrivilege = new Set(Types::String);
// Loop thru the duties to get privileges
setEnumerator = setDuty.getEnumerator();
while (setEnumerator.moveNext())
{
treeNodeDutyNew = treeNodeDuty.AOTfindChild(setEnumerator.current()).AOTfirstChild();
treenodeT = new TreeNodeTraverser(treeNodeDutyNew, false);
while(treenodeT.next())
{
setPrivilege.add(treenodeT.currentNode().AOTname());
}
}
// Loop thru the privileges to get Entry points
setEnumerator = null;
setMenuItem = new Set(Types::String);
setEnumerator = setPrivilege.getEnumerator();
while (setEnumerator.moveNext())
{
treeNodePrivNew = treeNodePriv.AOTfindChild(setEnumerator.current()).AOTfirstChild();
treenodeT = new TreeNodeTraverser(treeNodePrivNew, false);
while(treenodeT.next())
{
setMenuItem.add(treenodeT.currentNode().AOTname());
}
}
// loop thru the menu items to get the properties
setEnumerator = null;
setEnumerator = setMenuItem.getEnumerator();
while (setEnumerator.moveNext())
{
name = setEnumerator.current();
select firstOnly1 modelelement
where modelelement.Name == name
&& (modelelement.ElementType == enum2int(UtilElementType::OutputTool) ||
modelelement.ElementType == enum2int(UtilElementType::ActionTool) ||
modelelement.ElementType == enum2int(UtilElementType::DisplayTool));
switch (modelelement.ElementType)
{
case enum2int(UtilElementType::OutputTool) :
path = #MenuItemsOutputPath;
break;
case enum2int(UtilElementType::ActionTool) :
path = #MenuItemsActionPath;
break;
case enum2int(UtilElementType::DisplayTool) :
path = #MenuItemsDisplayPath;
break;
default :
path = '';
break;
}
if (path)
{
select modelElementType where modelelementtype.TreeNodeName == path;
treeNodeObj = infolog.findNode(path).AOTfindChild(name);
menuLabelName = treeNodeObj.AOTgetProperty('Label');
menuName = treeNodeObj.AOTgetProperty('Name');
engLabel = SysLabel::labelId2String(treeNodeRole.AOTgetProperty('Label'), 'en-us');
frLabel = SysLabel::labelId2String(treeNodeRole.AOTgetProperty('Label'), 'fr');
engDescription = SysLabel::labelId2String(treeNodeRole.AOTgetProperty('Description'), 'en-us');
frDescription = SysLabel::labelId2String(treeNodeRole.AOTgetProperty('Description'), 'Fr');
treeMenu = infolog.findNode(#MenusPath);
treenodeT = new TreeNodeTraverser(treeMenu, false);
securityMenuPath = ' ';
while(treenodeT.next())
{
if(treeNodeT.currentNode().AOTfindChild(SysLabel::labelId2String2(menuLabelName)))//objLabel.extractString(menuLabelName)))
{
securityMenuPath = treenodeT.currentNode().treeNodePath();
}
}
securityPrivilege = conPeek(getPrivilegeDetails(roleAOTName, menuName),1);
securityDuty = conPeek(getPrivilegeDetails(roleAOTName, menuName),2);
roleAccess = conPeek(getPrivilegeDetails(roleAOTName, menuName),3);
maintainlicenseType = treeNodeObj.AOTgetProperty('MaintainUserLicense');
viewlicenseType = treeNodeObj.AOTgetProperty('ViewUserLicense');
configurationkey = treeNodeObj.AOTgetProperty('ConfigurationKey');
commaTextIo.write(roleName,roleAOTName,engLabel, engDescription, modelElementType.Name, treeNodeObj.AOTname(), objLabel.extractString(menuLabelName), securityDuty, securityPrivilege, roleAccess);
}
CodeAccessPermission::revertAssert();
}
}
*This post is locked for comments