Skip to main content
Solved

Filtering Branch Lookup by Current Organization in Acumatica

  • April 29, 2026
  • 6 replies
  • 56 views

Forum|alt.badge.img+2

I am trying to customize a Branch lookup in Acumatica so that it only shows branches belonging to the currently logged-in user's organization.

When a user opens the Branch selector, it should display only branches that belong to the same organization as the current branch.

The following SQL query returns the correct result:

SELECT *
FROM Branch
INNER JOIN Branch AS Br
ON Br.OrganizationID = Branch.OrganizationID
WHERE Br.BranchID = 22;

Here, 22 represents the current logged-in branch (AccessInfo.BranchID in Acumatica).

I tried to convert the same logic into BQL, but the result returns duplicate records instead of the expected filtered list.
 

 

Below are some of the approaches I tried: I also tried several other variations by making small changes, such as modifying the join type and other conditions, but I still ended up with the same result.
Following is the BranchAlies

public class BranchAlias : PX.Objects.GL.Branch { }

 

        [PXSelector(typeof(Search2<
Branch.branchID,
InnerJoin<BranchAlias,
On<BranchAlias.organizationID, Equal<Branch.organizationID>, And<BranchAlias.branchID, Equal<Current<AccessInfo.branchID>>>>>

>),
SubstituteKey = typeof(Branch.branchCD),
DescriptionField = typeof(Branch.acctName)
)]

[PXSelector(typeof(Search2<
Branch.branchID,
LeftJoin<
BranchAlias,
On<
BranchAlias.organizationID,
Equal<Branch.organizationID>
>
>,
Where
<BranchAlias.branchID,
Equal<Current<AccessInfo.branchID>>>

>),
SubstituteKey = typeof(Branch.branchCD),
DescriptionField = typeof(Branch.acctName)
)]


 

Best answer by Naveen Boga

@PDharmasena10  

 

I have implemented a custom selector to address this requirement and validated its behavior through testing. The solution is working as expected and correctly filters the data.

Please find the code and supporting screenshots attached for your reference.

 

using PX.Data;
using PX.Objects.AR;
using PX.Objects.GL;
using PX.Objects.GL.DAC;
using System.Collections;

namespace PX.Objects.FS
{
public class ServiceOrderEntryAccessRestExtP : PXGraphExtension<PX.Objects.FS.ServiceOrderEntry>
{
#region Event Handlers
protected virtual void _(Events.CacheAttached<FSServiceOrder.salesPersonID> e) { }
[PXMergeAttributes(Method = MergeMethod.Append)]
[BranchByOrganizationSelectorAttribute]
protected virtual void _(Events.CacheAttached<FSServiceOrder.branchID> e) { }
#endregion
}

public class BranchByOrganizationSelectorAttribute : PXCustomSelectorAttribute
{
public BranchByOrganizationSelectorAttribute()
: base(typeof(Branch.branchID))
{
SubstituteKey = typeof(Branch.branchCD);
DescriptionField = typeof(Branch.acctName);
}

protected virtual IEnumerable GetRecords()
{
int? currentBranchID = PXAccess.GetBranchID();
Branch currentBranch = PXSelect<
Branch,
Where<Branch.branchID, Equal<Required<Branch.branchID>>>>
.Select(_Graph, currentBranchID);

if (currentBranch == null)
yield break;
foreach (Branch branch in PXSelect<
Branch,
Where<Branch.organizationID, Equal<Required<Branch.organizationID>>>>
.Select(_Graph, currentBranch.OrganizationID))
{
yield return branch;
}
}
}
}

 

 

 

 

 

6 replies

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • April 29, 2026

@PDharmasena10  I have not verified, but can you please try below and check?

[PXSelector(
typeof(Search2<
Branch.branchID,
InnerJoin<Organization,
On<Branch.organizationID, Equal<Organization.organizationID>>>,
Where<
Branch.organizationID,
Equal<
Search<
Branch.organizationID,
Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>
>
>
>
>),
SubstituteKey = typeof(Branch.branchCD),
DescriptionField = typeof(Branch.acctName)
)]

 


Forum|alt.badge.img+2
  • Author
  • Semi-Pro II
  • April 29, 2026

Hi ​@Naveen Boga,
It gives bellow error. 
cannot be used as type parameter 'Operand' in the generic type or method 'Equal<Operand>'. There is no implicit reference conversion from 'PX.Data.Search<PX.Objects.GL.Branch.organizationID, PX.Data.Where<PX.Objects.GL.Branch.branchID,
I think it is not allowed to use Search<> inside Equal<>. 


Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • April 29, 2026

@PDharmasena10  Can you please share the code file here?


Forum|alt.badge.img+2
  • Author
  • Semi-Pro II
  • April 29, 2026

Hi ​@Naveen Boga,
 

namespace PX.Objects.FS
{
public class BranchAlias : PX.Objects.GL.Branch { }
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class ServiceOrderEntryAccessRestExtP : PXGraphExtension<PX.Objects.FS.ServiceOrderEntry>
{
#region Event Handlers
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(SalesPersonAttribute))]
[SalesPerson(typeof(Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>),
typeof(InnerJoin<Branch, On<Branch.organizationID, Equal<SalesPersonAccessRestExtP.usrInternalCompanyID>>>))]
protected virtual void _(Events.CacheAttached<FSServiceOrder.salesPersonID> e) { }

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(PXSelectorAttribute))]
[PXSelector(typeof(Search2<
Branch.branchID,
InnerJoin<BranchAlias,
On<Branch.organizationID, Equal<BranchAlias.organizationID>,
And<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>>>),
SubstituteKey = typeof(Branch.branchCD),
DescriptionField = typeof(Branch.acctName)
)]
protected virtual void _(Events.CacheAttached<FSServiceOrder.branchID> e) { }


#endregion

}


}

 


Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Answer
  • April 29, 2026

@PDharmasena10  

 

I have implemented a custom selector to address this requirement and validated its behavior through testing. The solution is working as expected and correctly filters the data.

Please find the code and supporting screenshots attached for your reference.

 

using PX.Data;
using PX.Objects.AR;
using PX.Objects.GL;
using PX.Objects.GL.DAC;
using System.Collections;

namespace PX.Objects.FS
{
public class ServiceOrderEntryAccessRestExtP : PXGraphExtension<PX.Objects.FS.ServiceOrderEntry>
{
#region Event Handlers
protected virtual void _(Events.CacheAttached<FSServiceOrder.salesPersonID> e) { }
[PXMergeAttributes(Method = MergeMethod.Append)]
[BranchByOrganizationSelectorAttribute]
protected virtual void _(Events.CacheAttached<FSServiceOrder.branchID> e) { }
#endregion
}

public class BranchByOrganizationSelectorAttribute : PXCustomSelectorAttribute
{
public BranchByOrganizationSelectorAttribute()
: base(typeof(Branch.branchID))
{
SubstituteKey = typeof(Branch.branchCD);
DescriptionField = typeof(Branch.acctName);
}

protected virtual IEnumerable GetRecords()
{
int? currentBranchID = PXAccess.GetBranchID();
Branch currentBranch = PXSelect<
Branch,
Where<Branch.branchID, Equal<Required<Branch.branchID>>>>
.Select(_Graph, currentBranchID);

if (currentBranch == null)
yield break;
foreach (Branch branch in PXSelect<
Branch,
Where<Branch.organizationID, Equal<Required<Branch.organizationID>>>>
.Select(_Graph, currentBranch.OrganizationID))
{
yield return branch;
}
}
}
}

 

 

 

 

 


Forum|alt.badge.img+2
  • Author
  • Semi-Pro II
  • April 29, 2026

HI ​@Naveen Boga,
Thanks for your support. that’s work fine.