Friday, March 21, 2014

How to get User Roles for different available companies in AX 2012 X++

//How to get User Roles for different available companies


static void UserRolebyCompany(Args _args)
{

    TextIo              txIoRead,txIoWrite;
    FileIOPermission    fioPermission;
    container           containFromRead;
    int                         xx,iConLength;
    str                         sTempPath,sFileName = "UserRolebyCompany.txt", sOneRecord;
    SecurityUserRole     SecurityUserRole;
    SecurityUserRoleCondition   SecurityUserRoleCondition;
    SecurityRole         SecurityRole ;
    UserInfo             userInfo;
    Company              comp;
    container            cont;
    ;

    //To Get the temporary file path.
    sTempPath = WINAPI::getTempPath();
    info("File is at: " + sTempPath + sFileName);

    // Assert permission for file.
    fioPermission = new FileIOPermission
        (sTempPath + sFileName ,"RW");
    fioPermission.assert();

    // If the test file already exists, delete it.
    if (WINAPI::fileExists(sFileName))
    {
        WINAPI::deleteFile(sTempPath + sFileName);
    }
 
    // "W" mode overwrites existing content, or creates the file.
    txIoWrite = new TextIo( sTempPath + sFileName ,"W");
        while select SecurityUserRole
    {
        cont = conNull();
        select SecurityRole  where SecurityRole .RecId == SecurityUserRole.SecurityRole;
        select userInfo where userInfo.id == SecurityUserRole.User;
        while select SecurityUserRoleCondition where SecurityUserRoleCondition.SecurityUserRole

== SecurityUserRole.RecId
        {
              cont += SecurityUserRoleCondition.DataArea;
        }
        if(!cont)
        {
            txIoWrite.write(strFmt("%1 -- %2 -- %3 -- %4 -- %5 -- %6",userInfo.name,

userInfo.networkAlias,userInfo.company,SecurityUserRole.User, SecurityRole .Name,"ALL"));
        }
        else
        {
            txIoWrite.write(strFmt("%1 -- %2 -- %3 -- %4 -- %5 -- %6",userInfo.name,
userInfo.networkAlias,userInfo.company,SecurityUserRole.User, SecurityRole

.Name,con2StrUnlimited(cont, ',')));
        }
    }
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...