Skip to main content
Question

How to determine which Company a specific user has access to in Acumatica?

  • September 3, 2026
  • 2 replies
  • 14 views

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?

 

2 replies

Forum|alt.badge.img+5
  • Jr Varsity II
  • September 3, 2026

Hi ​@vishalr53 ,

Yes, using PXLoginScope in combination with PXAccess.GetAvailableOrganizationIDs() is an excellent and recommended approach to get this information in Acumatica.

Because a user's access to Companies (Organizations) and Branches in Acumatica is determined by a complex combination of Roles, Access Rights, and explicit Branch Access settings, querying the database tables directly (like UserBranch or role tables) can be tedious and prone to missing edge cases.

 

protected virtual void Users_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
    Users row = (Users)e.Row;
    if (row == null || string.IsNullOrEmpty(row.Username)) return;

    // e.TranStatus == PXTranStatus.Completed ensures the user is successfully saved first
    if (e.TranStatus == PXTranStatus.Completed) 
    {
        // 1. Enter the scope of the user being created/modified
        using (new PXLoginScope(row.Username))
        {
            // 2. Get the Organization IDs available to THIS user
            int[] availableOrgIDs = PXAccess.GetAvailableOrganizationIDs();
            
            // 3. Process your logic
            foreach (int orgID in availableOrgIDs)
            {
                // e.g., mapping logic, synchronization, or logging
            }
        }
        // The scope automatically reverts to the actual logged-in user here
    }
}


jinin
Pro I
Forum|alt.badge.img+12
  • Pro I
  • September 3, 2026

Hi ​@vishalr53 ,

Yes — that's the right approach. There's no overload of GetAvailableOrganizationIDs() that takes a username, so PXLoginScope is the only public way to get it for another user.

Two things to watch:

Call it after commit, not during persist. Use RowPersisted with e.TranStatus == PXTranStatus.Completed — otherwise the login scope may not see role/restriction rows from the same uncommitted transaction and you get a stale list.
Wrap it in try/catch. It throws for users who can't log in (disabled, locked out, no role in the tenant, API-only accounts).

GetAvailableOrganizationIDs() returns Organizations (CS101500) within the current tenant. If you mean tenant, this isn't the right API.