static void CopyRolesFromUserToAnotherUser(Args _args)
{
SecurityRole securityRole;
SecurityUserRole securityUserRoleSource;
SecurityUserRole securityUserRoleDestination;
SecurityUserRole securityUserRoleDestinationNew;
boolean added;
UserId sourceUserId = 'User 1';
UserId destinationUserId = 'User 2';
str getFormattedRoleName(str _roleName)
{
return SysLabel::labelId2String2(_roleName, CompanyInfo::languageId());
}
while select securityUserRoleSource
where securityUserRoleSource.User == sourceUserId
join securityRole
where securityUserRoleSource.SecurityRole == securityRole.RecId
notexists join securityUserRoleDestination
where securityUserRoleDestination.SecurityRole == securityRole.RecId
&& securityUserRoleDestination.User == destinationUserId
{
info(strFmt('Adding role %1 to the user %2.', getFormattedRoleName(securityRole.Name), destinationUserId));
securityUserRoleDestinationNew.clear();
securityUserRoleDestinationNew.User = destinationUserId;
securityUserRoleDestinationNew.SecurityRole = securityRole.RecId;
securityUserRoleDestinationNew.AssignmentMode = RoleAssignmentMode::Manual;
securityUserRoleDestinationNew.AssignmentStatus = RoleAssignmentStatus::Enabled;
SecuritySegregationOfDuties::assignUserToRole(securityUserRoleDestinationNew, null);
}
}
This posting is provided "AS IS" with no warranties. Use code at your own risk.
No comments:
Post a Comment