Solved

Call Void action for Checks and Payment item


Userlevel 4
Badge +3

Hi,

I need to add to my application logic that will Void Checks and Payments items which have “closed” state

When I try to do this programmatically via this code

I get error in this event, which is called when I try to call Void action 

This event is located in this path : C:\Program Files\Acumatica ERP\AcumaticaDB_new\App_Data\CodeRepository\PX.Objects\AP\APPaymentEntry.cs

The reason why I get object reference in this event is that NewValue filed is null and can’t look from which place we transfer PXFieldVerifyingEventArgs object to this event, because thought all call stack from my code to this Class I receive these errors

So I can’t investigate from which place null is coming to the event

Besides, this is Acumatica code, change it in any way will be bad idea, maybe there is something that must be added in my code and will help to fix object reference in the event.

The version of Acumatica is 2021R2

Thanks in advance.

icon

Best answer by markusray17 6 July 2022, 00:00

View original

42 replies

Userlevel 6
Badge +6

I was able to reproduce your issue locally and just debugged it myself.

            APPaymentEntry graph = PXGraph.CreateInstance<APPaymentEntry>();

graph.Document.Current = graph.Document.Search<APPayment.refNbr>(YourRefNbr);

graph.UnattendedMode = false;

try
{
graph.voidCheck.Press();
}
catch (PXRedirectRequiredException) { }


graph.release.Press();

So I had to set the UnattendedMode to false on the graph after instantiating it. There is an event handler that doesn’t set the value of the AdjdCuryRate field if the UnattendedMode is set to true(it interprets that as an internal call).

You will also want to catch the redirect exception and then release the document afterwards. 

Userlevel 6
Badge +6

You already added that

graph.APPost.Current = graph.APPost.SelectSingle();

The Update and Insert methods aren’t changing the values, they raise events and event handlers modify the values. One of those event handlers is setting that value to null during:

Adjustments.Update(adj);

What I am saying is using the call stack and debugger you can see the method chain when that value is set to null and then figure out which event handler is the cause and why. 

That being said if it is working in the UI for the same record the issue is likely with the surrounding code or the context from which you are invoking the action. 

Userlevel 6
Badge +6

That would seem to be a bug on 21R2, I’d check with Acumatica and see what they say. I was able to replicate it on my 21R2 instance. The same issue doesn’t seem to be happening with ARPayments. I’m guessing there is an issue with how they are checking for documents being out of balance for APPayments.

 

It could be related to your issue, but I would expect to get the same error via code as in the UI. 

Userlevel 6
Badge +6

You are trying to view the source of the call stack for the Acumatica code which you don’t really need to do. The call stack will show the method calls leading up to the error. Attempting to inspect the source of the method calls won’t work unless you are decompiling Acumatica code. 

Presumably you already checked that the field isn’t null on the APAdjust object so something would have to be setting it to null. You can put a debug point on the DAC setter and then look at the call stack to determine where it is getting set to null. You could also create your own event and intercept it there(again looking at the call stack).

I would also verify that manually triggering the action isn’t causing the same error. That would indicate that something is going wrong when you are initiating the graph before calling the action.

Also I’m probably repeating myself but Voiding and Reversing the Application are not the same thing. Reversing applications will re-open the payment but not void it. Voiding the payment will reverse applications as well as cancel the payment. You are saying you want to void the payment yet you are calling ReverseApplication above. 

Userlevel 6
Badge +6

What is the status of the ap payment you are trying to void?

Userlevel 6
Badge +6

I would probably recommend stepping through the VoidCheck method. It sounds like something might be going wrong there. Assuming it succeeds it would create a voiding document and set the current document to that new voiding document. That is the document you want to release. If that method skips or fails to create that document it would be attempting to release the original closed check which is why I think you are getting that error.

Userlevel 6
Badge +6

The VoidCheck method is a method in APPaymentEntry, what you posted was the PressImpl code. You should be setting a breakpoint at the top of the VoidCheck method and then walking through it. 

Userlevel 6
Badge +6

You extended APReleaseProcess instead of APPaymentEntry.

Userlevel 6
Badge +6

You have to release the document afterwards, reverse application just creates the reversal under Documents to Apply. APAdjust is the adjustment that you are reversing(APPost is the view where you are setting the current APAdjust). 

You don’t really need to see the actual value, you just need to figure out what methods are changing the value(visible in the call stack).

Userlevel 4
Badge +3

You have to release the document afterwards, reverse application just creates the reversal under Documents to Apply. APAdjust is the adjustment that you are reversing(APPost is the view where you are setting the current APAdjust). 

You don’t really need to see the actual value, you just need to figure out what methods are changing the value(visible in the call stack).

Hi @markusray17 

I found that I missed that instruction that you provided previously

[GRAPH NAME].[VIEW NAME].Current = [Record]

I do not know what must be in VIEW NAME and Record

Please, suggest what I should add here

Userlevel 4
Badge +3

Hi @markusray17 

Thanks for provided explanation and code sample.

Void action executes without any troubles, but during graph.release.Press(); row debug throws exception

it gives error at this location

Unfortunately the the debugger cant show current apdoc status value

What should I change in order to solve this ?

Userlevel 4
Badge +3

What is the status of the ap payment you are trying to void?

@markusray17 

“Closed” state

 

Userlevel 4
Badge +3

I would probably recommend stepping through the VoidCheck method. It sounds like something might be going wrong there. Assuming it succeeds it would create a voiding document and set the current document to that new voiding document. That is the document you want to release. If that method skips or fails to create that document it would be attempting to release the original closed check which is why I think you are getting that error.

@markusray17 

I entered to this method

In what part exactly document creation is happening 

Userlevel 4
Badge +3

The VoidCheck method is a method in APPaymentEntry, what you posted was the PressImpl code. You should be setting a breakpoint at the top of the VoidCheck method and then walking through it. 

@markusray17 

At this part

    APPayment voidcheck = Document.Search<APPayment.refNbr>(Document.Current.RefNbr, APPaymentType.GetVoidingAPDocType(Document.Current.DocType));

void check is null

this part gives error at that part

 

Userlevel 6
Badge +6

That’s exactly what it should be doing.

 

Try overriding the Release method on APPaymentEntry and then inspecting the invoices, something like:

        public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);

[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
foreach(APPayment apdoc in adapter.Get<APPayment>())
{
var inv = apdoc;
}

return baseMethod(adapter);
}

You would need to put the above code inside a graph extension for APPaymentEntry but that should allow you to inspect the apdoc variable without it being optimized away. It should be a void check with a balanced status.

Userlevel 4
Badge +3

That’s exactly what it should be doing.

 

Try overriding the Release method on APPaymentEntry and then inspecting the invoices, something like:

        public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);

[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
foreach(APPayment apdoc in adapter.Get<APPayment>())
{
var inv = apdoc;
}

return baseMethod(adapter);
}

You would need to put the above code inside a graph extension for APPaymentEntry but that should allow you to inspect the apdoc variable without it being optimized away. It should be a void check with a balanced status.

It will not allow me to modify ApPaymentEntry due to Acumatica project can not be fully built with all packages , I built only my solution, not Acumatica site . It gives hundred errors when I try to built Acumatica website

 

Userlevel 6
Badge +6

You shouldn’t be modifying APPaymentEntry, you would put that code into a graph extension of APPaymentEntry. If you have trouble with that the Open University has courses on extending/modifying graph logic(T210 I believe). 

Userlevel 4
Badge +3

@markusray17 

Ok

One moment to clarify - why it is needed to call release after voidcheck action ? In interface I just pressed Void button and it created copy of existing payment, why in code we must use release ?

 

Userlevel 6
Badge +6

It’s not a copy it is a voiding document. To void a check the system creates a Voided Check document that mirrors the original check, until that document is released though the original check is not voided.

Userlevel 4
Badge +3

Hi @markusray17 

I checked manually in UI reverse application action and it worked.

You were right, the error happens after this part as you mentioned : “I would suspect it is happening in the Adjustments.Update call after the AdjgCuryInfoID value is set.”

You suggested me that DAC for my case will be APAdjust class, where exactly I should set a breakpoint ? I do not know which field is responsible for putting null to NewValue field 

Userlevel 6
Badge +6

Its the AdjdCuryRate field on the APAdjust DAC(in the APAdjust.cs file).

If it works in the UI I would recommend double checking the surrounding code. Make sure you are getting the correct APPayment set as current and the correct APAdjust set. Assuming those are correct calling the action from code should be almost identical to clicking the button in the UI. 

Also where exactly are you executing this code from?

Userlevel 4
Badge +3

Hi @markusray17 

I have an extended Payment entity

However the debug does not step here after action calls

 

Userlevel 4
Badge +3

You extended APReleaseProcess instead of APPaymentEntry.

@markusray17 It is needed to use APReleaseProcess to support my custom logic

Maybe there is again some issue with parameters as it was with voidCheck method ?

Userlevel 4
Badge +3

@markusray17

After void payment has status Hold

I tried to set balanced manually but it did not help

 

Userlevel 6
Badge +6

You probably have the Hold Documents on Entry option selected in the AP Preferences.

You would have to use the Remove Hold action before releasing then. 

 

The reason for extending APPaymentEntry wasn’t related to your business logic it was a temporary method to allow you intercept and debug the Release call.

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 — 2023  Acumatica, Inc. All rights reserved