How to copy roles from one user to another in Dynamics AX2012

Updated: 19.02.2014

Today we would like to share How to copy roles from one user to another in Dynamics AX2012.

Code example:

    #static void assignRolesFromUserToUser(Args _args)
    #{
    #    #define.fromUserId('Kudryavc')
    #    #define.toUserId('ax12test')
    #
    #    SecurityRole            securityRole;
    #    SecurityUserRole        securityUserRoleFrom,securityUserRoleTo;
    #    ;
    #    while select securityUserRoleFrom
    #        where   securityUserRoleFrom.User               == #fromUserId
    #            &&  securityUserRoleFrom.AssignmentStatus   == RoleAssignmentStatus::Enabled
    #        join securityRole
    #        where   securityRole.RecId                      == securityUserRoleFrom.SecurityRole
    #    {
    #        select securityUserRoleTo
    #            where securityUserRoleTo.SecurityRole == securityUserRoleFrom.SecurityRole &&
    #                securityUserRoleTo.User == #toUserId;
    #
    #        if (!securityUserRoleTo || securityUserRoleTo.AssignmentStatus != RoleAssignmentStatus::Enabled)
    #        {
    #            SysSecHelper::log('Adding ' + securityRole.Name);
    #
    #            securityUserRoleTo.User = #toUserId;
    #            securityUserRoleTo.SecurityRole = securityRole.RecId;
    #            securityUserRoleTo.AssignmentMode = RoleAssignmentMode::Manual;
    #            securityUserRoleTo.AssignmentStatus = RoleAssignmentStatus::Enabled;
    #
    #            if (SecuritySegregationOfDuties::assignUserToRole(securityUserRoleTo, null) )
    #            {
    #                EePersonalDataAccessLogging::logUserRoleChange(securityRole.RecId,0, #toUserId, AddRemove::Add);
    #            }
    #            else
    #            {
    #                SysSecHelper::log('Skipping ' + securityRole.Name);
    #            }
    #        }
    #        else
    #        {
    #            SysSecHelper::log('Skipping ' + securityRole.Name);
    #        }
    #    }
    #
    #}


 

 

Other blog posts

14.11.2017
Why outsourcing company is more effective than In-house IT-specialists There are situations when in-house specialists spend most of their time awaiting requests or they cannot get their work...
26.09.2017
Microsoft Dynamics AX program decisions are constantly improving. At first, innovations come to European companies, and only after that to Russian enterprises.We aspire to be one step ahead in this...
28.08.2017
Notes of the summit and of Dynamics market in Russia. Neti has been specializing in AX development since 2003. Our sphere of interest is the cutting-edge MS Dynamics technology. We find, study...

Subscribe for blog updates

Get updated with our blog new articles via your email!


Subscribe now