I am updating a purchase order with AIF and receiving the following error when I try to update the order a second time.
“Cannot edit a record in Purchase order lines (PurchLine). An update conflict occurred due to another user process deleting the record or changing one or more fields in the record.”
The error is throwing from the class PurchLineType. The update works perfectly when I update once OR if I only have 1 line on the purchase order.
Any ideas on where the code might be trying to update twice or is getting the wrong RecVersion?
Thanks!
I’ll try to explain how this problem occurs. Imagine this situation:
- You read a record from database with RecVersion 1 and store it in two buffers.
- You update the first buffer and write it to DB. AX checks that RecVersion in DB is still 1, therefore it’s save to update the record. RecVersion is changed to 2.
- You take the other buffer with RecVersion 1 and try to update it in DB. AX finds that RecVersion isn’t what we originally read from DB, i.e. 1. It means that somebody changed the record in the meantime and if we continued, the previous update would be lost. That would lead to corrupted data, therefore AX doesn’t perform the update and throws an error.
The problem is that the third step uses a buffer with outdated data. You should read fresh data from DB (by a select statement or by calling reread()) before updating them.
Your other option would be handling the exception, refreshing data and doing the update again, but it wouldn’t be a wise a choice in this case. Your update conflict seems to be caused by a flawed application design, not by users concurrently working on same data.
I am performing another read between step 2 and 3. Would the original buffer still be read?
This is my test case.
-
Create Purchase order with 2 lines.
-
Read purchase order.
-
Send in update with a qty changed on line 1. (works fine)
-
Read purchase order.
-
Send in update with a qty changed on line 2. (throws the error)
I’ve tried to reread the purchLine table before the ‘prepareForSaveExtended’ returns true and processes the record but that reverts all the values and doesn’t take the new qty amount. I’ve put this reread in several different spots in the method but haven’t been successful.
Unless you understand what’s causing the problem, you can’t fix it. Put a breakpoint to PurchLine.update() and check from which places the record is being updated.
Hi Michelle;
Were you able to find a solution for this? I am facing the exact same problem.
Hi TC,
I see that you didn’t get a reply from Michelle, but did you end up finding a solution to this on your own? I am now facing this problem as well.