CacheLookup while loop delete

Hello,

Am having trouble with a while loop on a table buffer that uses caching. Essentially, we used the Copy Item Prices function in AX2012 to copy standard costs from a legacy costing version to our new version for 2014.

This copied over all prices however, so if a product had many activations in a given costing version, all were brought over. We would like to only activate the latest price per product.

A product may have more than one valid record for Product Master configurations ( we use Revisions A, B, C, etc. ). So item #001 may have a cost for A, B, C. If “C” had 2 prices in legacy costing version, we want to delete the one with the oldest date.

Unfortunately, with my job, if we have two “C” prices, they both are deleted…it seems the cache is not updated upon delete?

Here is my job:

InventItemPriceSim pendingPricesBase,pendingPricesCompare;

ttsBegin;

pendingPricesBase.disableCache(true);

while select pendingPricesBase

order by pendingPricesBase.FromDate desc

where pendingPricesBase.VersionId == ‘2013’

{

ttsBegin;

pendingPricesCompare.disableCache(true);

delete_from pendingPricesCompare

where pendingPricesCompare.VersionId == pendingPricesBase.VersionId

&& pendingPricesCompare.ItemId == pendingPricesBase.ItemId

&& pendingPricesCompare.InventDimId == pendingPricesBase.InventDimId

&& pendingPricesCompare.RecId != pendingPricesBase.RecId;

ttsCommit;

}

ttsCommit;

info(‘done’);

I resolved this by using two variables for dimensionId and itemId. I then check if the dimension != previous or the item != previous. If it is the exact same from the cache, I skip the inner loop.

Kind of ugly, but it works in a pinch.

Hi Silvano,

Can you post the final code that you’ve fixed to delete the old record from the InventItemPriceSim Table please.