Skip to main content
Solved

Mystery filtering on a graph

  • May 15, 2024
  • 8 replies
  • 160 views
  • Translate All

Forum|alt.badge.img+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?

Best answer by darylbowman

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}");
}

 

View original

8 replies

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

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);

     

Translate

Forum|alt.badge.img+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.

Translate

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

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

Translate

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

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.

Translate

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

I’m curious what happens if you try this:

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

 

Translate

Forum|alt.badge.img+1

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

Translate

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

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}");
}

 

Translate

Forum|alt.badge.img+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.

Translate