Skip to main content
Question

How to Retrieve the Current Organization's BAccount When No Branch Exists

  • October 15, 2026
  • 1 reply
  • 16 views
  • Translate All

Forum|alt.badge.img+2

I'm working on an Acumatica customization where I need to retrieve the BAccount associated with the current branch. If there is no branch configured and the instance has only an organization, I need to retrieve the organization's BAccount instead. And i working in a single tenant instance

I'm currently using the following code:

PXAccess.MasterCollection.Branch currentBranch =
PXAccess.GetBranch(PXAccess.GetBranchID());

BAccount bAccount =
BAccount.PK.Find(Base, currentBranch.BAccountID);

BAccountQAExt branchQAExt =
bAccount?.GetExtension<BAccountQAExt>();

if (branchQAExt == null)
{
string msg =
"Return warehouse or location is not configured for this branchID.";

throw new PXException(msg);
}

This works correctly when the organization has branches. However, when the instance has only an organization and no branches, BAccount.PK.Find() returns null.

I verified the following through debugging and by checking the database directly:

  • PXAccess.GetBranch(PXAccess.GetBranchID()) returns a currentBranch object.

  • currentBranch.BAccountID contains the correct BAccountID associated with the organization.

  • The corresponding BAccount record exists in the database.

  • Despite this, BAccount.PK.Find(Base, currentBranch.BAccountID) returns null when there are no branches.

I also tried querying BAccount directly using BQL:

BAccount bAccount = SelectFrom<BAccount>
.Where<BAccount.bAccountID.IsEqual<@P.AsInt>>
.View.Select(Base, currentBranch.BAccountID);

I encountered the same issue.

My questions:

  1. Is there a difference in how Acumatica handles the organization's BAccount compared with a branch's BAccount?

  2. Is PXAccess.GetBranch() the correct way to retrieve the current organization or branch context when an organization has no branches?

  3. What is the recommended way to retrieve the organization's BAccount when no branch exists?

Any guidance or examples would be appreciated.

Thank you!

1 reply

darylbowman
Captain II
Forum|alt.badge.img+17

Have you tried using Branch.OrganizationID instead?

Translate