Solved

Call Void action for Checks and Payment item


Userlevel 4
Badge +2

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 4
Badge +2

hi @markusray17 

I am sincerely  grateful for all provided help, thank you for your professionalism and patience.

I have accomplished logic that I must have been implemented.

Best regards 

Userlevel 6
Badge +5

There’s no reason to put the voided check on hold, you can just check if it is on hold and then if it is call the release from hold action. 

You have asked this a few times now but:

Reversing the applications will move a payment from closed → open. Voiding a payment will reverse the applications and cancel the payment moving it from closed → voided. There is no way to move a payment from closed → balanced. 

If the payment is still closed then the voiding didn’t work, judging from your screenshot the voided checks didn’t get released.

If you need to reverse payments you will likely run into an error(“document is out of balance”) I believe they are changing it in future versions but currently the system doesn’t allow AP payments with open balances. Meaning you would have to reverse and re-apply the payment at the same time in order to persist it. 

Also I have probably said it before but I would suggest you take a step back from the code and take a second to understand what you are doing and what you are trying to accomplish. You seem to be unsure on whether you want to re-open payments or cancel them and you seem to have little understanding about how the payments work in the system. I can try to point you in the right direction but your lack of understanding is likely to result in problems for you down the line. This is also one of the more complicated and sensitive parts of the system so you really don’t want any potentially critical bugs. 

Userlevel 4
Badge +2

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.

This code partly solved my issue

It voided some payments if I missed removefromhold and release steps

At this screen 001989 and 001989 items were voided 

But if I leave all my code to execute payment will appear closed 

What I must change in order to make payment availble after hold ? I mean to make it open or balanced (justnot being closed)

Userlevel 6
Badge +5

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.

Userlevel 4
Badge +2

@markusray17

After void payment has status Hold

I tried to set balanced manually but it did not help

 

Userlevel 4
Badge +2

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 6
Badge +5

You extended APReleaseProcess instead of APPaymentEntry.

Userlevel 4
Badge +2

Hi @markusray17 

I have an extended Payment entity

However the debug does not step here after action calls

 

Userlevel 6
Badge +5

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 +2

@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 +5

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 +2

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 +5

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 +2

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 +5

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 4
Badge +2

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 6
Badge +5

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 4
Badge +2

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

@markusray17 

“Closed” state

 

Userlevel 6
Badge +5

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

Userlevel 4
Badge +2

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 6
Badge +5

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 4
Badge +2

Hi @markusray17 

The required logic has changed a little bit.

I need to use Void instead of Reverse Application.

I checked Void work in Acumatica UI for payment and it worked with no troubles, item was successfully saved.

However in code I receive same error in same place

Previously you advised to check this place : Adjustments.Update(adj);

Concerning Reverse Application it was right, the error appeared right after that place

However with Void the debug does not come here

Concerning that part : “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.”

I cant see exactly from which place error comes due to Acumatica files are not available to view

I can only check the call stack, but it is not informative

This is my code

string referenceNbr = "001991";
 APPaymentEntry graph = PXGraph.CreateInstance<APPaymentEntry>();
  graph.Document.Current = graph.Document.Search<APPayment.refNbr>(referenceNbr);               
  graph.voidCheck.Press();

Userlevel 4
Badge +2

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. 

Thank you for the response, I will write to Acumatica and let you know, when I get the response

Userlevel 6
Badge +5

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 4
Badge +2

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. 

Hi @markusray17 

Previously, I checked in UI reverse application and it worked,

As I discovered now, it returns Closed state to Open, but it does not allow to save it in UI with this error 

How payment should be modified to resolve this error ?

Can this be the cause of my problem ?

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