Skip to main content
Solved

Is it possible to extend a PXLongOperation?

  • December 18, 2024
  • 9 replies
  • 194 views
  • Translate All

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

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. 

View original

9 replies

Dmitrii Naumov
Community Manager
Forum|alt.badge.img+7

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

Translate

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

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;
}

 

Translate

Dmitrii Naumov
Community Manager
Forum|alt.badge.img+7

​@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.

Translate

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

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.

Translate

Dmitrii Naumov
Community Manager
Forum|alt.badge.img+7

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

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

Translate

Dmitrii Naumov
Community Manager
Forum|alt.badge.img+7

​@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. 

Translate

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

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

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

Translate

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

Got it. Thank you!

Translate