Skip to main content
Answer

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

  • August 31, 2022
  • 3 replies
  • 296 views

Forum|alt.badge.img+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

Best answer by scottstanaland12

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

3 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • August 31, 2022

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.


Forum|alt.badge.img+1
  • Author
  • Jr Varsity III
  • Answer
  • August 31, 2022

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


Forum|alt.badge.img+1

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