Solved

Mystery filtering on a graph


Userlevel 4
Badge +1

Hello,

I want to make some changes to fields when the Parent Account field is updated on the CustomerMaint graph.

public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
{
protected virtual void _(Events.RowUpdated<Customer> e)
{
if (e == null) return;
Customer customer = e.Row;
if (e.Row.ParentBAccountID != e.OldRow.ParentBAccountID && e.Row.ParentBAccountID != null)
{
BAccount bAccount = Base.Select<BAccount>().FirstOrDefault(x => x.BAccountID == customer.ParentBAccountID);
//bAccount is returned when the parent BAccount is a customer
//bAccount is null when the parent BAccount is a supplier
//do things
}
}
}

I’ve created an extension and I’m using the code above to get the BAccount record of the selected Parent Account. Problem is, when the Parent Account is a supplier the BAccount is not returned, when the Parent Account is a customer to works.

If I add the following code, it worked for both suppliers and customers, but Acumatica doesn’t like graphs being created in events.

var g = new PXGraph();
BAccount bAccount3= g.Select<BAccount>().FirstOrDefault(x => x.BAccountID == customer.ParentBAccountID);

I assume that something in the CustomerMaint graph is filtering out suppliers but I’m not sure what.

Can anyone explain why this is happening and suggest a workaround?

icon

Best answer by darylbowman 16 May 2024, 15:51

View original

8 replies

Badge +11

Two questions: 

  1. Is there a reason you’re using RowSelected<BAccount> instead of FieldUpdated<BAccount.ParentBAccountID>?
  2. Base.Select is a linq query rather than a database query. To be honest, I’m not sure why it’s working at all, but that’s not necessarily surprising. Have you tried using a regular query:
    var parentAccount = BAccount.PK.Find(Base, customer.ParentBAccountID);

     

Userlevel 4
Badge +1

Hello - the code has been updated to use PK.Find as suggested. Sadly, the same thing happens. I’m sure that the Base graph (CustomerMaint) is somehow filtering the results to show only customers but I have no idea why.

public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
{
protected virtual void _(Events.RowUpdated<Customer> e)
{
if (e == null) return;
Customer customer = e.Row;
if (e.Row.ParentBAccountID != e.OldRow.ParentBAccountID && e.Row.ParentBAccountID != null)
{
BAccount bAccount = BAccount.PK.Find(Base, customer.ParentBAccountID);
//bAccount is returned when the parent BAccount is a customer
//bAccount is null when the parent BAccount is a supplier
//do things
}
}
}

I’m using RowUpdated rather than FieldUpdated because I want to update other caches. This particular problem occurs in both events.

Badge +11

Then I’ll just crawl over into your boat if that’s ok.

Userlevel 4
Badge

Hi @stephenward03 ,

I'm not sure if it's worth mentioning, but I've been looking into the code and noticed that the Customer ID field is using the CustomerRaw attribute from the Customer DAC, while for the Vendor ID, it's using the VendorRaw attribute in the Vendor DAC. So, those fields only fetch corresponding BAccounts.

Badge +11

I’m curious what happens if you try this:

BAccount bAccount = BAccount.PK.Find(Base, customer.ParentBAccountID, PKFindOptions.SkipGlobalCache);

 

Userlevel 4
Badge +1

Happy to try anything! Same result I’m afraid. Customers return data, Suppliers return null. It is very odd.

Badge +11

I can’t tell you why this works, but I can tell you THAT it does:

if (row.ParentBAccountID != e.OldRow.ParentBAccountID && row.ParentBAccountID != null)
{
var parentBAccount = BAccountParent.PK.Find(e.Cache.Graph, (int)row.ParentBAccountID);
if (parentBAccount is object)
throw new PXException($"{parentBAccount.AcctName}");
}

 

Userlevel 4
Badge +1

It certainly does work. BAccountParent is the correct object to query. Seems completely bizarre that BAccount didn’t work but there you go. I’d love to understand why but we may never know. Thank you for sticking with this problem and finding a solution.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved