Solved

How to access Cache data within a TransactionScope

  • 25 April 2022
  • 1 reply
  • 350 views

Userlevel 7
Badge +8

I have a method which is called after Acumatica original method is invoked. I know Acumatica’s base method when invoked, updates an existing record, creates another record with ifferent status and saves the changes. What I’m doing is to run some additional validations and if validations passed then allow to Acumatica’s base method be completed. To make this happen, I have enveloped everything into a TransactionScope. At the end either the whole process will be commited or rejected. I have put partial my code below. My problem is when I run the code outside the PXTransactionScope I can access both updated and inserted record and modify but when it is run inside the TransactionScope as they are not saved to DB after Acumatica’s base nmethod is invoked i can not access them and modify. I need this to happen inside a TS. I tried to access the Cache to see if the inserted and updated records are in Cache (Base.DACView.Cache.Cached) but I do not see the modification is passed to Cach either. Can someone help me please how can I access the Cache changes in my below code within the TS?

public PXAction<APInvoice> customAction;
[PXButton(CommitChanges = true, DisplayOnMainToolbar = true, IsLockedOnToolbar = true)]
[PXUIField(DisplayName = "My Action", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true, Visible = true)]


protected virtual IEnumerable CustomAction(PXAdapter adapter)
{
using (PXTransactionScope ts = new PXTransactionScope())
{
//Execute Acumatica Original Method
Base.AcumaticaAction.Press();

// Return if Cancel Button pressed.
if (DialogData.AskExt() != WebDialogResult.OK)
{
return adapter.Get();
}

// Do some valdation stuff here and modify the oiginally created data by Acumatica

if validation not passed
{
ts.Dispose();
}

Base.Save.Press();
ts.Complete();
}

return adapter.Get();
}

 

icon

Best answer by darylbowman 25 April 2022, 14:19

View original

1 reply

Badge +10

I don't believe you can use the current context (Base) to modify in this situation. Initialize a new graph and load the record you're trying to save. If changes are to be made, make the changes in the new graph instance and save that way. Only use Base to GET values. SET values in the new graph instance.

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