Skip to main content
Question

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

  • October 15, 2026
  • 3 replies
  • 38 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!

3 replies

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

Have you tried using Branch.OrganizationID instead?

Translate

KrunalDoshi
Pro I
Forum|alt.badge.img+9

Hi ​@PDharmasena10,

In your single-tenant Acumatica instance, the important distinction is between the current branch context, the organization, and the business account (BAccount) associated with either one.

Even when an organization has no branches, Acumatica can still have an organization record and its associated business account. The fact that PXAccess.GetBranch() returns an object does not necessarily mean that its BAccountID can be resolved through BAccount.PK.Find() in that configuration.

I recommend resolving the organization explicitly through Organization.OrganizationID, then using its BAccountID.

Organization organization = SelectFrom<Organization>
.Where<Organization.organizationID
.IsEqual<@P.AsInt>>
.View.Select(Base, currentBranch.OrganizationID);

int? bAccountID = organization?.BAccountID
?? currentBranch.BAccountID;

Hope this helps!

 

Translate

Dipak Nilkanth
Pro III
Forum|alt.badge.img+14

Hi ​@PDharmasena10,
could you please try below code snippet ? let us know your results.
 

int? branchID = PXAccess.GetBranchID();

YourGraph backgroundGraph =
PXGraph.CreateInstance<YourGraph>();

PX.Objects.GL.Branch currentBranch = branchID != null
? PX.Objects.GL.Branch.PK.Find(backgroundGraph, branchID)
: null;

PX.Objects.CR.BAccount bAccount = null;

if (currentBranch != null)
{
bAccount = PX.Objects.CR.BAccount.PK.Find(
backgroundGraph,
currentBranch.BAccountID);

if (bAccount == null)
{
PX.Objects.GL.DAC.Organization organization =
SelectFrom<PX.Objects.GL.DAC.Organization>
.Where<
PX.Objects.GL.DAC.Organization.organizationID
.IsEqual<@P.AsInt>>
.View.Select(
backgroundGraph,
currentBranch.OrganizationID);

if (organization != null)
{
bAccount = PX.Objects.CR.BAccount.PK.Find(
backgroundGraph,
organization.BAccountID);
}
}
}


return bAccount.BAccountID;

Hope, it helps!

Translate