Solved

Unable to Update value in the PXLongRun Operation

  • 22 March 2023
  • 8 replies
  • 190 views

Userlevel 3
Badge

Hello Everyone,

In the persist delegate, I would like the custom field inside the PXLong Run operation but value is not updating. Can anyone help me on this?

If try to save again, it is re-calling the Persist method and going to the infinite loop.

Here is the sample code for your reference.

 

      public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
baseMethod();
if (Base.Document.Current != null)
{
PXLongOperation.StartOperation(Base, delegate ()
{
try
{
//my custom logic is here

//Updating the custom field value below, value is holding in the caches but updating

Base.Document.Cache.SetValue<SOOrderExt.usrCustomField>(Base.Document.Current, true);
Base.Document.Cache.Update(Base.Document.Current);
}
catch (Exception ex)
{
throw ex;
}
}

}

}

 

icon

Best answer by Naveen Boga 27 March 2023, 13:22

View original

8 replies

Userlevel 7
Badge +8

Can you elaborate why are you running LongOpr in Persist?

can you provide a background and the use case you are trying to achieve apparently in the Sales Order entry?

I don’t recall if I have ever seen the LongOpr timer appears on any screen when we click on Save.

Userlevel 3
Badge

Hi @aaghaei  Thanks for your response.

We are using LongRun operation because, we are creating the some transactions like (IN Receipts), hence it is suggestable to use the LongRun to run on a separate thread.

It is very common in Sales Order screen to use the LongRun when we have some custom/API related logic, Have you never worked any Tax plug-ins, you can see the long run in the SO.

 

 

Userlevel 7
Badge +8

I have not worked with tax plug-ins so cannot be of help on this. Sorry.

I have worked plenty with the PXLongOperation but have not seen it in the Persist which is invoked when Save is pressed.

On a side note, I might be missing something but just looked into the SOOrderEntry graph and all its extensions but couldn’t find any PXLongOperation in Persist or its Delegate.

Userlevel 7
Badge +5

You might then consider calling PXDatabase.Update to update your custom field to avoid calling Persist the second time.

Userlevel 5
Badge +1

@nsmith51 Have you tried placing the basemethod() after the LongOperation process?

Userlevel 7
Badge +10

Hi @nsmith51 ,

Can you please try below code snippet to update your custom field.

I am not verified this code, but it will helps to implement your logic for long operation.

public delegate void PersistDelegate();
    [PXOverride]
    public virtual void Persist(PersistDelegate baseMethod)
    {
        baseMethod();

        if (Base.Document.Current != null)
        {
            PXLongOperation.StartOperation(Base, delegate
            {
               CustomMethod();
            });
        }
    }

public void CustomMethod()
    {
try
{

      //your logic is here to update the custom field

    catch (Exception e)
        {
            throw new PXOperationCompletedWithErrorException(e.Message);
        }

        graph.Update();
        graph.Persist();
}

Hope, this helps!

Regards,

Sweta

Userlevel 7
Badge +17

Hi @nsmith51  If you write such updates it won’t persist, once LongRun is completed then the caches will be cleared in this.

You can create a new graph instance, and fill in the current details into the new graph and do updates with this graph, and save.

Userlevel 3
Badge

Understood. Thanks for the help @Vinay Koppula @Naveen Boga @Django @aaghaei @sweta68 

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