Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Job to fix intercompany orders delivery reminder leaves a purchTable record locked

(0) ShareShare
ReportReport
Posted on by 45

Hi everyone,

I am a developer working on a job that my customer needs to fix some wrong intercompany orders. Don't ask me why or how they have done it, as I don't know what they have done to have this situation: I just know that they have some intercompany orders not aligned in delivery remain quantities between the purchase and the sales order and I have been ask for a job that should show a dialog to select a specific purchase or sales order and a lot ID and update its delivery reminder fields to zero.

After some work I have managed to get the job work: tested on the first purchase line of a purchase order, it puts zero on the right fields and still keep the intercompany connections and the rest of the orders fields safe.

But if I load the job a second time and use it to fix a second line of the same purchase order, then I get the error "Cannot edit a record in Purchase orders (PurchTable). An update conflict occurred due to another user process deleting the record or changing one or more fields in the record."

It seems that the first execution of the job leaves the updated purchTable record occupied, and it cannot be updated or deleted anymore, and I am not able to understand why: I put all the modifications to database fields insite da ttsbegin-ttscommit block, so when the first execution of the jobs finish it should unlock any of the used records.

I have read somewhere on this forum that when "delivery reminder" functionality is in use, sometimes this thing could happen... but still I don't know how to fix my job to avoid this.

Is there anyone here that can help? Do you need any more informations?

Thank you!

  • Job to fix intercompany orders delivery reminder leaves a purchTable record locked
    Hi Andrea,
    have you solved the problem?
    I have a similar request from a customer.
    Thank you
    Jessica
  • Martin Dráb Profile Picture
    Martin Dráb 230,817 Most Valuable Professional on at
    RE: Job to fix intercompany orders delivery reminder leaves a purchTable record locked

    I moved the thread to Dynamics 365 Finance Forum.

    I know little about your code, but let me demonstrate a typical example of what may happen. You can use the debugger to analyze your particular scenario.

    Here is the typical case:

    1. You read PurchTable record to a variable (e.g. pt). RecVersion is (say) 1.

    2. You update a PurchLine record. Some code called from on PurchLine.update() updates some information on PurchTable too, which gets a new RecVersion.

    3. Then you use your pt variable to update the status. The system checks whether the version in DB is still 1 and therefore the update can be safely done, and it finds that RecVersion changes and the update could lead to data loss/inconsistency. Therefore it throws an exception.

    The right approach in this case is loading the PurchTable record from DB after it was updated by PurchLine.update().

  • RE: Job to fix intercompany orders delivery reminder leaves a purchTable record locked

    Hi Martin!

    I am using dynamics 365 version 10.0.29.

    I am still developing the job, so we are talking about a cloud-hosted dev machine: no other users are using it at the same time as me.

    As said, the job works on just one specific purchline retrieved through lot ID, but it updates the purchline and purchtable status too in the process. Everything is inside a tts block, so if anything goes wrong it can do a rollback to the original situation.

    First time the job works well and with no error. Then, if I use it again on another purch line of the same order (same purch ID and different Lot ID) I get the error. But it's a completely different and separated execution of the job, it can happens hours later from the first one and the problem is the same. So, I don't think there is other executing code that conflicts. But maybe I am wrong...

  • Martin Dráb Profile Picture
    Martin Dráb 230,817 Most Valuable Professional on at
    RE: Job to fix intercompany orders delivery reminder leaves a purchTable record locked

    First of all, which version of AX is it about?

    You get an update conflict when you read record from database and before you save it (update()), the record in database gets changed. It may be done by another user, but it might also by your own code updating the same record through a different table buffer.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans