web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Issue in Multithreaded Batch Job – SQL Duplicate Key Exception in InventSum

(5) ShareShare
ReportReport
Posted on by 105

We are facing an issue with a custom multithreaded batch job in D365FO that processes data and creates transfer/movement journals.

The error occurs during standard journal posting logic:
Violation of PRIMARY KEY constraint 'I_7874ITEMDIMIDX'. Cannot insert duplicate key in object 'dbo.INVENTSUM'.

The problem occurs when multiple threads try to update the InventSum table simultaneously, leading to the error.
Exception handling is in place, including Exception::DuplicateKeyException, but the error is not being caught. Some records remain unprocessed due to this failure.

Has anyone encountered a similar issue with InventSum in multithreaded processing? What best practices can be followed to handle concurrency on InventSum and prevent duplicate key conflicts in a multi-threaded batch job?

Looking forward to insights from the community. Thanks in advance!

Categories:
I have the same question (0)
  • Mohamed Amine Mahmoudi Profile Picture
    26,434 Super User 2025 Season 2 on at
     
    Can you plase share with us the x++ code ?
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    You shouldn't be getting DuplicateKeyException on update, because you shouldn't be updating the primary key. I think it's either not an update or you're doing a wrong thing. 
  • CU10030917-0 Profile Picture
    105 on at
     
    Thank you for the reply.
     
    We are using the standard class to post movement journals, and the error occurs within the posting logic.
    Each thread in multithread creates and posts single movement journal.
    Primary key of InventSum is ItemId and InventDim. There could be a case where two threads have same itemId & InventDim and are trying to post journals same time, resulting in this error.
     

     
    Please share your insights.
     
    Thanks!
     
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    As you see knowing just that the error occurs within the posting logic isn't detailed enough. You can't address the problem because you don't know what the problem actually is. You next step should be finding where exactly the exception gets thrown.
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    You need to share more information about the problem so that the community can help you.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans