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

Announcements

News and Announcements icon
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,803 Super User 2026 Season 1 on at
     
    Can you plase share with us the x++ code ?
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    239,660 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
    239,660 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,674 Super User 2026 Season 1 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 676

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 635 Super User 2026 Season 1

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 605 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans