Solved

FieldUpdated Doesn't pickup the change when happens in PXLongOperation

  • 5 January 2023
  • 8 replies
  • 233 views

Userlevel 7
Badge +8

Hello All,

 

I have a Field updated Event Handler that calls a method. It works fine until the change to the field comes from a PXLongOperation. To be more specific, on APInvoice the status field is updated by the different actions. All actions and status changes are monitored just fine until I Release the document (Status changes from Balanced to Open). This is when the handler misses the change possibly because it is running in a separate thread/scope. Below is the Handler I have. How can make the handler listen to the change from PXLongOperation too?

protected void _(Events.FieldUpdated<APInvoice, APInvoice.status> e)
{
if (e.Row == null) return;
SyncStatusTransitionLog(Base, e.OldValue, e.NewValue);
}

 

icon

Best answer by Dmitrii Naumov 10 January 2023, 16:28

View original

8 replies

Userlevel 5
Badge +1

yes, you can wait until all operations finish their work on threads, and then you can do you logic with field, use this method:

PXLongOperation.WaitCompletion(Base.UID);

method also returns bool status if you need it, and method blocks timer on UI of screen, mostly this method is usable in back-end logic.

Here is my example of use:

 

I hope it will help you

Userlevel 7
Badge +8

@andriikravetskyi35 

Thank you for the insight. I am calling the method inside the Event handler and my problem is the Event is not fired so how I can make the event wait for Long Operation completion when event is not fired to execute whatever code I put in?

Userlevel 5
Badge +1

if event is not fired, it seams that logic of LongOperation changes value of Status field by SetValue()  method of cache, and this method doesn’t trigger updating events and compiler doesn’t run your event.

Maybe try to run your method additionally in RowPersisting event (old Status value is in DB, new Status value will be in cache)

Userlevel 7
Badge +8

@andriikravetskyi35 

I tried to resolve the issue using 

  • Persist(PersistDelegate baseMethod)
  • _(Events.FieldUpdated<APInvoice, APInvoice.status> e)
  • _(Events.RowUpdated<APInvoice> e)
  • _(Events.RowPersisting<APInvoice> e)
  • _(Events.RowPersisted<APInvoice> e)

to monitor the Document Status Change but no luck. The latest Status is firing the events is Balanced and then the LogOperation timer starts counting and when finished the Document Status changes to Open but no event is being fired. I tried different methods of getting Old and New value for the Status field including the below but no luck.

APInvoice DocumentNew = Base.Document.Current;
APInvoice DocumentOld = Base.Document.Cache.GetOriginal(Base.Document.Current) as APInvoice;
 

Any ideas how I can listen to the Status change which is happening inside the LongOperation?

@Dmitrii Naumov @smarenich @vkumar @Naveen Boga 

 

Userlevel 7
Badge +5

@aaghaei so, I assume the change happens in scope of a different graph, right?

In that case I think you have two options:

  1. Either add an event to that other graph and execute the code there
  2. Or have the requirement implemented in a business event rather then in code.

 

What is the scenario you are trying to implement?

Userlevel 7
Badge +8

@Dmitrii Naumov 

Thank you for the response.

We are having a problem with Acumatica Status Transition Workflow and Approval Map Workflow. Same as the Approval Workflow I need to monitor the Status change and insert a record into EPApproval to track and monitor the time between each step of the workflow. I have developed the engine and it works on over 20 of Acumatica’s screens that need to be monitored. The only issue I am facing is when the transition from one Status to another happens within the Scope of a PXLongOperation. From training courses of processing screen i recall this specific operation works synchronic and creates its own session and what happens the Even Handlers of the current instance doesn’t pick up the change of the Long Operation.

Based on what you are suggesting I can append the actions within the LongOperations but I will lose the generic usage of the code I have and each screen will need some extra manipulation and of course extra maintenance.

Regarding the business event I am not sure I can achieve this generic need and if yes then how. That will be great if you could share a sample if you have any.

Userlevel 7
Badge +5

Well, for that specific purpose I feel like you may need to have custom push notification subscriber and process the changes in that subscriber. It’ll be pretty generic (the only non-generic part will be the push notification configuration itself, while code can be the same)

https://help-2022r2.acumatica.com/(W(16))/Help?ScreenId=ShowWiki&pageid=2cdef9b1-d4ef-48b4-8a92-093e7ea39552

Userlevel 7
Badge +8

Thanks @Dmitrii Naumov really appreciated

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