Solved

Opportunity Persist Products.Cache.Cached not cleared when adding a new record

  • 31 August 2022
  • 3 replies
  • 155 views

Userlevel 2
Badge +1

I have a customization on the Opportunities screen that overrides the Persist() method.

Basically the code is iterating the Products.Cache.Cached collection and checking if a particular inventory item is added and also calculating the total amount of the the extended price.

If the item does not exist a new line is added and populated with a calculation using the total.

This is all working very well, but i've noticed an issue where the Products.Cache.Cached collection 
contains values from previously loaded records.

For example if I have an opportunity loaded on screen with 3 lines with a total of $500, and I select the add new record toolbar button.  Once i enter the required fields on the new record and save. The total of 500 is being pulled from the previous opportunity and my new line is added based on the 
total 500 when it should be 0 because no lines have been added to the new opportunity.

Any idea why the cache is not clearing when adding a new record.  Any way I can work around it.

Thanks
Scott

icon

Best answer by scottstanaland12 31 August 2022, 19:26

View original

3 replies

Userlevel 7
Badge +5

First of all, I’d not recommend iterating through Cached collection ever.

If you want to iterate through Inserted/Updated records, you can iterate through respective collections. 

If you want to iterate through all records in the current document, you can iterate through [ViewName].Select().

 

Iterating through ‘Cached’ may yield some unexpected results.

Userlevel 2
Badge +1

Hi Dmitrii,

Thanks for the suggestion.  I switched to using view.Select() and that resolved the issue.

I was not sure if it was ok to use the vew.Select() in the Persist event, I thought it may not contain the un persisted rows.

 

Scott

Userlevel 4
Badge +1

Great tip from Dmitrii - solved a similar issue for me. 

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