如何在 Ax 2012 中获取公司用户访问列表?

How to get a list of Companies User Access in Ax 2012?

在 Ax 2009 中,要按用户获取公司列表,我是这样获取的:

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;
}

但是在 Ax 2012 中,我没有 CompanyDomainList table,我怎样才能获得用户有权访问的公司列表?

用户和公司信息保存在 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];
    }
}