Skip to main content
Solved

Is it possible to extend a PXLongOperation?

  • December 18, 2024
  • 9 replies
  • 121 views

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

I've encountered a couple situations recently where I needed to extend an action where a PXLongOperation was running and do something after it was completed. I can use PXLongOperation.WaitCompletion(Base.UID) to wait for it to finish, but it seems to break the operation (the processing indicator doesn’t appear until the operation is complete). I think this makes sense, since it's blocking the UI thread until the background thread is complete.

What is the proper way to execute additional code after a PXLongOperation is “finished” without blocking the UI thread?

Best answer by Dmitrii Naumov

@darylbowman you can redefine it in the extension as non-static. Please see in the article. There is an example of a static method redefined there. 

9 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 18, 2024

@darylbowman can you just put your additional processing in the end of the existing LongOperation instead? 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • December 18, 2024

The current situation looks like this:

Original code:

public virtual IEnumerable release(PXAdapter adapter)
{
PXLongOperation.StartOperation(this, delegate()
{
ReleaseProcess(graph, doc);
});
// Need my code to run here because I can't extend ReleaseProcess
// but PXLongOperation must be finished first
}

protected static void ReleaseProcess(PXGraph graph, Document doc)
{

}

The best I’ve come up with is this:

public delegate IEnumerable releaseDelegate(PXAdapter adapter);  
[PXOverride]
public virtual IEnumerable release(PXAdapter adapter, releaseDelegate baseMethod)
{
DateTime? releaseDate = View.Current?.ReleaseDate;

var result = baseMethod(adapter);

// But this breaks the operation indicator
PXLongOperation.WaitCompletion(Base.UID);

var newGraph = PXGraph.CreateInstance<MyGraph>();
doc = newGraph.View.Current = newGraph.View.Search<Doc.orderNbr>(doc?.OrderNbr);
if (doc is object)
{
newGraph.View.SetValueExt<Doc.dateReleased>(doc, releaseDate);
newGraph.View.Update(doc);
newGraph.Actions.PressSave();
}

return result;
}

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 18, 2024

@darylbowman well, there is probably some part inside ReleaseProcess that you can override. We usually make sure release is easy to piggyback on. 

 

But also, you can just call the ReleaseProcess from your override instead of calling the baseMethod.


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • December 18, 2024

But also, you can just call the ReleaseProcess from your override instead of calling the baseMethod.

I got errors doing that because it’s protected.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 18, 2024

darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • December 18, 2024

The method is static. A static member cannot be marked as abstract.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • December 18, 2024

@darylbowman you can redefine it in the extension as non-static. Please see in the article. There is an example of a static method redefined there. 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • December 18, 2024

​...you can redefine it in the extension as non-static...

This I did NOT know. Extremely helpful. I think this might work.


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • December 18, 2024

Got it. Thank you!