Skip to main content

Notifications

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 47

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:
  • Martin Dráb Profile Picture
    232,508 Most Valuable Professional on at
    Issue in Multithreaded Batch Job – SQL Duplicate Key Exception in InventSum
    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.
  • CU10030917-0 Profile Picture
    47 on at
    Issue in Multithreaded Batch Job – SQL Duplicate Key Exception in InventSum
     
    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
    232,508 Most Valuable Professional on at
    Issue in Multithreaded Batch Job – SQL Duplicate Key Exception in InventSum
    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. 
  • Mohamed Amine Mahmoudi Profile Picture
    19,820 Super User 2025 Season 1 on at
    Issue in Multithreaded Batch Job – SQL Duplicate Key Exception in InventSum
     
    Can you plase share with us the x++ code ?
     
    Best regards,
    Mohamed Amine MAHMOUDI

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,356 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,508 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans