X++ job to get user assigned security roles

static void Job6(Args _args)
{
    SecurityInfoTable axpUserSecurityTmp;
    SecurityUserRole securityUserRole;
    SecurityRole securityRole;
    SecurityTask securityTask;
    UserInfo     userInfo;

    SecurityRoleAllTasksView securityRoleAllTasksView;

    OMUserRoleOrganization roleOrganization;
    OMInternalOrganization internalOrganization;

    while select securityUserRole
       outer 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

    {
        axpUserSecurityTmp.User = securityUserRole.User;
        axpUserSecurityTmp.RoleName = SysLabel::labelId2String(securityRole.Name);

        if(axpUserSecurityTmp.RoleName == "")
        {
            axpUserSecurityTmp.RoleName = securityRole.Name;
        }

        axpUserSecurityTmp.TaskName = securityTask.Name;
        axpUserSecurityTmp.OrganizationName = internalOrganization.Name ? internalOrganization.Name : "All Company";
        axpUserSecurityTmp.UserName = userInfo.name;
        axpUserSecurityTmp.insert();
    }

}

Comments

Popular posts from this blog

AX 2012 DEVOPS Build, Release setup and configuration

AX 2012 Build process using AZURE DEVOPS

What is Microsoft Power Platform?