Hello
I am working on a customization where I need to determine which Company a specific user has access to.
The requirement is:
- A user can have access to one or more Company.
- When the user is created or modified, I need to retrieve the Organization ID that user currently has access to.
For example,:
private List<int> GetAccessibleOrganizationIDs(PX.SM.Users user)
{
int?[] organizationIDs;
using (new PXLoginScope(
$"{user.Username}@{PXAccess.GetCompanyName()}"))
{
organizationIDs = PXAccess.GetAvailableOrganizationIDs();
}
return organizationIDs
.Where(x => x.HasValue)
.Select(x => x.Value)
.Distinct()
.ToList();
}
Is PXLoginScope + PXAccess.GetAvailableOrganizationIDs() the recommended way to get Organization ID for specific user?