Solved

Clicking the Process button on the Recalculate Customer Balances screen from code

  • 8 September 2022
  • 11 replies
  • 226 views

Userlevel 6
Badge +3

I am making updates to various tables in AR.  After making the changes, I want to recalculate customer balances using the ARIntegrityCheck graph.  

I created the graph instance.  My goal is to “check” the box on the customer number I want to recalculate.  After I initialize the graph, all of the caches are empty.  When you open the screen, the grid is populated with all the customer id’s.  I thought that by creating the graph instance, the caches would be populated through the events on the graph.

I’ve tried everything I can think of to get the graph “loaded”.

As per below, I am trying to get a current record for the customer number I am updating.  I set the checkbox to true for Selected and update the current.

At the end, I click the Process button using a technique I found on Stackoverflow.  I get a PXAction exception because I don’t think there is an “action” on the graph I can call.

var arIntegrityCheck = PXGraph.CreateInstance<ARIntegrityCheck>();

//arIntegrityCheck.Load();
//arIntegrityCheck.Actions.PressCancel();
//arIntegrityCheck.Clear();
arIntegrityCheck.Filter.Current.FinPeriodID = "201201";

arIntegrityCheck.Customers.View.RequestRefresh();
arIntegrityCheck.ARCustomerList.View.RequestRefresh();

Customer cust = SelectFrom<Customer>.Where<Customer.bAccountID.IsEqual<ARRegisterFilter.toCustomerID.FromCurrent>>.View.Select(this);

arIntegrityCheck.Customers.Current = arIntegrityCheck.ARCustomerList.Select(cust);
arIntegrityCheck.Customers.Current.Selected = true;
arIntegrityCheck.Customers.UpdateCurrent();
arIntegrityCheck.ARCustomerList.SetProcessEnabled(true);

try
{
arIntegrityCheck.Actions["Process"].Press();
}
catch (Exception e)
{
string joe = "joe";
}

I think there are two problems:

  1. I can’t figure out how to get the graph created and get the Views populated
  2. I don’t know how I can fire the Process button to do the work on the selected customer.

Any guidance would be appreciated.

icon

Best answer by Gabriel Michaud 9 September 2022, 21:00

View original

11 replies

Userlevel 7
Badge +10

Joe,

 

I’m sure you’re aware already, but this process is meant to correct unexpected integrity errors; not as part of a regular process. What are you editing that requires you to run this process? Could it be achieved using standard Acumatica processes instead of directly updating tables?

Userlevel 6
Badge +3

Hi @Gabriel Michaud, unfortunately, no.  Acumatica does not provide the functionality to do what I am looking to do.  

Acumatica ERP is a seen by some as a step down from other ERP systems because of the lack of functionality to merge customer accounts.  People have been asking for this feature for 6 years or more.  I am seeing what it would take to make a program to allow clients to merge customers accounts.

It is a pretty nasty job as there are so many working parts to the application.  I can see why this is not a feature at this time.  

The program I am working on is not intended for general use.  I am trying to make a tool that can be used during the implementation process where customer accounts get imported into Acumatica and duplicates can be merged.  

I am just in the “see what I can do” phase.  At this point, it seems like it is working.  Now I am trying to programmatically run the reconciliation process so that you don’t have to do them one at a time.  I am really uncomfortable doing it this way, but for very basic implementations (not manufacturing etc.) this could prove to be very worthwhile.

Or, Acumatica could make a feature to do this.  That would be even better. 😉

Userlevel 7
Badge +10

Thanks for the detailed response. I like to hack things too and I see you did your homework already 😀. 

I think what is missing in your code is arIntegrityCheck.ARCustomerList.Select() to initialize the primary view of the graph. I don’t think you should be working with any other view.

As an alternative, you could also invoke ARIntegrityCheck.IntegrityCheckProc directly -- it is a protected method, so you will have to use reflection or work with PXProtectedAccess in a graph extension (not sure about 2nd option, I never used this attribute but I believe it would also help you achieve the same thing)

Userlevel 6
Badge +3

Thanks Gabriel for not blasting me for going rogue.  Ha!

Just for kicks, I tried calling the IntegrityCheckProc directly.

                var arReleaseProcess = PXGraph.CreateInstance<ARReleaseProcess>();
                Customer cust = SelectFrom<Customer>
                    .Where<Customer.bAccountID.IsEqual<ARRegisterFilter.toCustomerID.FromCurrent>>
                    .View.Select(this);
                arReleaseProcess.IntegrityCheckProc(cust, "201201");
Crazy thing is, I got the exact same errors as before.

Here’s my solution.  I’m going to create a report that gets kicked out at the end of the processing and tell the customer to use the built in screen to update the balances with a listing of customer numbers affected.

I love to make things way more complicated than they need to be.

Note, this program will probably never see the light of day, but I HAVE to take a shot at it.

Userlevel 7
Badge +10

The code in ARIntegrityCheck is not the same as ARReleaseProcess… did you try the other graph?

Userlevel 6
Badge +3

I think so. 

I used the PXGraph.CreateInstance<ARReleaseProcess>(); and called the IntegrityCheckProc method in that graph.

I found something else that may actually have been causing my action to fail even after I removed the code to do the rebuild.

I’m trying some other things.  I’ll get back to you at the end of the day after I waste another 8 hours on this.  HAHA!  Seriously.  

Compile...restart website...debug...fail...think you are going to give up...try again because you can’t stop yourself...REPEAT.  Having the web site restart after every compile is a “day killer”.  😃

I am a Microsoft Vendor and my primary business is to host a web site for their Marketing division to do billing for Microsoft Events.  Covid temporarily killed my business so I have time to do this (and learn too!).

Userlevel 6
Badge +3

I don’t know why I didn’t see it sooner.  I can just call the method directly without trying to “push a button”.  I’m not using this code but it works in case anyone ever wants to do this (doubt anyone will).  The original rebuild screen has a great processing presentation.  No need to recreate it.

 

                //var arReleaseProcess = PXGraph.CreateInstance<ARReleaseProcess>();
                //Customer custFrom = SelectFrom<Customer>
                //    .Where<Customer.bAccountID.IsEqual<@P.AsInt>>
                //    .View.Select(graph, item.FromCustomerID);
                //arReleaseProcess.IntegrityCheckProc(custFrom, "190001");

Userlevel 7
Badge +10

@joe21 the process looks different in ARReleaseProcess than ARIntegrityCheck… if that works for you then great but thought I’d point out it’s not doing exactly the same things ;) 

Userlevel 6
Badge +3

The ARIntegrityCheck graph uses the IntegrityCheckProc which is located in the ARReleaseProcess graph.

If you set a debug point in the ARReleaseProcess class on the IntegrityCheckProc method, it gets fired from the Recalculate Customer Balances screen. 

From what I see, it would be the correct method to call.  I am making the same exact call to the IntegrityCheckProc method as the delegate in the ARIntegrityCheck graph.  

Also, when I do allow that code to execute, it produces the same results.  My ignorance about Acumatica is showing here.  I don’t understand why the IntegrityCheckProc method would be handled any differently if I call it the same way the ARIntegrityCheck graph is calling it. 

Ooops...other than the preserve time stamp...

Userlevel 7
Badge +10

I’m seeing something different on my end, the exact proc being called varies based on the screen ID where it’s being called from:

Here’s the actual logic being applied by ARIntegrityCheck:

 

Userlevel 6
Badge +3

That’s why my ignorance is showing.  :-)  

I just put a breakpoint in the ARReleaseProcess class on the IntegrityCheckProc method and I saw that it got fired from my code as well as from the Integrity screen.

This is even more reason for me NOT to use that code in my project and have the implementer use the screen that was designed to do the process.

Thanks @Gabriel Michaud for taking so much time to clarify this for me!!

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