AX 2012 Export user security role information to CSV file
static void VN_GetUserSecurityinfo(Args _args)
{
str fileName;
boolean HasRecord;
SecurityUserRole securityUserRole;
SecurityRole securityRole;
SecurityTask securityTask;
UserInfo userInfo;
SecurityRoleAllTasksView securityRoleAllTasksView;
OMUserRoleOrganization roleOrganization;
OMInternalOrganization internalOrganization;
TextIO io;
Str text;
FilePath sourceFilePath;
FileIOPermission perm;
#File
;
fileName = "C:\\TEMP\\securityrolesusers.csv";
perm = new FileIOPermission(filename, #IO_WRITE);
perm.assert();
text = 'User,RoleName, Organization,UserName\n';
while select securityUserRole
join securityRole
where securityRole.RecId == securityUserRole.SecurityRole
join userInfo
where userInfo.id == securityUserRole.User
&& userInfo.enable == NoYes::Yes
/* outer join securityRoleAllTasksView
where securityRoleAllTasksView.SecurityRole == securityUserRole.SecurityRole
outer join securityTask
where securityTask.RecId == securityRoleAllTasksView.SecurityTask*/
outer join roleOrganization
where roleOrganization.User == securityUserRole.User
&& roleOrganization.SecurityRole == securityUserRole.SecurityRole
outer join internalOrganization
where internalOrganization.RecId == roleOrganization.OMInternalOrganization
{
text+= strfmt('%1,%2,%3,%4\n',securityUserRole.User,securityRole.AotName,internalOrganization.Name ? internalOrganization.Name : "All Company",userInfo.name);
HasRecord = true;
}
if(HasRecord)
{
io = new TextIO(filename, #IO_WRITE,1252);
io.write(text);
info(strFmt("Exported to %1",filename));
}
}
{
str fileName;
boolean HasRecord;
SecurityUserRole securityUserRole;
SecurityRole securityRole;
SecurityTask securityTask;
UserInfo userInfo;
SecurityRoleAllTasksView securityRoleAllTasksView;
OMUserRoleOrganization roleOrganization;
OMInternalOrganization internalOrganization;
TextIO io;
Str text;
FilePath sourceFilePath;
FileIOPermission perm;
#File
;
fileName = "C:\\TEMP\\securityrolesusers.csv";
perm = new FileIOPermission(filename, #IO_WRITE);
perm.assert();
text = 'User,RoleName, Organization,UserName\n';
while select securityUserRole
join securityRole
where securityRole.RecId == securityUserRole.SecurityRole
join userInfo
where userInfo.id == securityUserRole.User
&& userInfo.enable == NoYes::Yes
/* outer join securityRoleAllTasksView
where securityRoleAllTasksView.SecurityRole == securityUserRole.SecurityRole
outer join securityTask
where securityTask.RecId == securityRoleAllTasksView.SecurityTask*/
outer join roleOrganization
where roleOrganization.User == securityUserRole.User
&& roleOrganization.SecurityRole == securityUserRole.SecurityRole
outer join internalOrganization
where internalOrganization.RecId == roleOrganization.OMInternalOrganization
{
text+= strfmt('%1,%2,%3,%4\n',securityUserRole.User,securityRole.AotName,internalOrganization.Name ? internalOrganization.Name : "All Company",userInfo.name);
HasRecord = true;
}
if(HasRecord)
{
io = new TextIO(filename, #IO_WRITE,1252);
io.write(text);
info(strFmt("Exported to %1",filename));
}
}
Comments
Post a Comment