Pages

March 17, 2014

How to get User Roles for different available companies

How to get User Roles for different available companies

Hi Friends,

Recently i come to a user requirement, they need all employees details with they roles and permission within different companies.

So here the code to fetch respective details in text file.



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 == sur.SecurityRole;
        select userInfo where userInfo.id == SecurityUserRole.User;
        while select surc 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, ',')));
        }
    }
}


You can fetch your records in Excel file also by modify your code.

-Harry

1 comment:

  1. Your blog was very helpful to get the programming languages related information for website design and development.I really grateful to this blog.
    Web Design Companies | Web Development Companies

    ReplyDelete

Thanks