Acumatica技术咨询:如何从Customer表获取AcctReferenceNbr并拼接至Projects表的External Ref. Nbr
Solution to Fetch Customer's AcctReferenceNbr in ProjectEntry
Let's fix this step by step. The core issue here is that you don't need to rely on the CustomerMaint graph to get the AcctReferenceNbr—you can directly query the related Customer/BAccount record using the CustomerID field from the PMProject row itself.
Correct Code Implementation
Update your ProjectEntry_Extension with this code:
namespace PX.Objects.PM { public class ProjectEntry_Extension : PXGraphExtension<ProjectEntry> { #region Event Handlers protected void PMProject_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { PMProject row = (PMProject)e.Row; if (row == null || row.CustomerID == null || string.IsNullOrEmpty(row.ContractCD)) return; // Fetch the related BAccount (Customer) record using CustomerID BAccount customer = PXSelectReadonly<BAccount, Where<BAccount.bAccountID, Equal<Required<PMProject.customerID>>>> .Select(Base, row.CustomerID); if (customer != null && !string.IsNullOrEmpty(customer.AcctReferenceNbr)) { // Combine AcctReferenceNbr with ContractCD (QuoteID) row.ExtRefNbr = $"{customer.AcctReferenceNbr}{row.ContractCD}"; } else { // Fallback if no customer or AcctReferenceNbr exists row.ExtRefNbr = row.ContractCD; } } #endregion } }
Key Explanations:
- Direct Data Query: We use
PXSelectReadonlyto fetch theBAccountrecord linked to the project'sCustomerID. SinceCustomeris a subclass ofBAccount,AcctReferenceNbris stored directly on theBAccounttable. - Null Safety: We added checks for null values (empty row, missing CustomerID, empty ContractCD) to prevent runtime errors.
- No Cross-Graph Dependency: You don't need to call methods from
CustomerMaint—querying the database directly fromProjectEntryis the standard Acumatica approach for accessing related records.
Why Your Previous Attempts Failed:
- Cross-Graph Static Method: Calling a static method from
CustomerMaintdoesn't work because that graph is tied to the Customer screen context, and you don't have a validBAccountrow from the Project screen's event args. - Incorrect Selector Usage:
PXSelectorAttribute.Selectis meant for interacting with a selector control on the current cache, not for fetching related records from another table.
内容的提问来源于stack exchange,提问作者Andrew Aiello
相关产品推荐
相关产品推荐

