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

时间:2015-09-14 16:51:40

标签: axapta dynamics-ax-2012 x++

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

但是在2012年的Axe中,我没有CompanyDomainList表,如何获得用户有权访问的公司列表?

1 个答案:

答案 0 :(得分:4)

用户和copmany信息保存在OMUserRoleOrganization表格中。

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