3

In Ax 2009, to get a list of companies by user I get it of this way:

static container getAllCompanies()
{
     Container companies;
     DataArea dataArea;
     CompanyDomainList companyDomainList;
     AccessRightsList  accessRightsList;
    UserGroupList        userGroupList;


//select all the companies in which current user’s access level is higer than NoAccess
     while select id,name from DataArea
           Exists join companyDomainList
           where companyDomainList.companyId == dataArea.Id
           join accessRightsList
           where accessRightsList.domainId   ==  companyDomainList.domainId && accessRightsList.accessType > AccessType::NoAccess
           join userGroupList
           where userGroupList.groupId       == accessRightsList.groupId && userGroupList.userId == curuserid()
     {
          companies += [dataArea.name,dataArea.Id];
     }

     return companies;
}

but in Ax 2012, I don't have the CompanyDomainList table, how can I get a list of companies that user has access?

halfer
  • 19,824
  • 17
  • 99
  • 186
Max Pinto
  • 1,463
  • 3
  • 16
  • 29

1 Answers1

4

User and copmany information is saved in the OMUserRoleOrganization table.

UserId userId = curUserId();

CompanyInfo companyInfo;
OMUserRoleOrganization oMUserRoleOrganization;
container result;

while select companyInfo
    exists join oMUserRoleOrganization
        where oMUserRoleOrganization.OMInternalOrganization == companyInfo.RecId
            && oMUserRoleOrganization.User == userId
{
    result += [companyInfo.Name, companyInfo.DataArea];
}

if (!result)
{
    // no specific company for user --> all
    while select companyInfo
    {
        result += [companyInfo.Name, companyInfo.DataArea];
    }
}
Matej
  • 7,517
  • 2
  • 36
  • 45