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

"Cannot create a record, the record already exist" error in LedgerJourTrans table

(1) ShareShare
ReportReport
Posted on by 26
While running a custom job in D365 FNO, getting weird error "Cannot create a record, the record already exist" in LedgerJournalTrans table. The job logic basically reads records from user tables and transforms each field into a rows in LedgerJourTable & LedgerJourTran. Weird part is 340 records are transformed, 285 are done correctly the last 55 records are throwing the above error.
But after the job is run, though it throws error, it gets saved in LedgerJourTable & LedgerJourTrans, and we can post this manually.
Your early reply is much appreciated.
I have the same question (0)
  • Martin Dráb Profile Picture
    240,492 Most Valuable Professional on at
    The error means that you're trying to insert a record that violates uniqueness of a unique index. For example, you're trying to insert a second journal with the same journal ID. It would result in invalid state of the database, therefore such an insert is rejected.
     
    Use the debugger to find out where exactly gets the error thrown from and which data the code is trying to insert at the moment. You can compare it with the data you already have in database (you may need to look at uncommitted data too).
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    I have taken the liberty to create a secret gist for us to aid readability and ensure that no viruses might come from the DOCX document: https://gist.github.com/jofme/a7500b5d8f9dfde038bb18cad6259580
     
    Two things come to mind:
    1: You are setting LineNum manually but are forgetting to add 1 to the new line number. This will give you issues with the 'NatualKeyIdx'.https://gist.github.com/jofme/a7500b5d8f9dfde038bb18cad6259580#file-floodportglsystemjob-cs-L161
     
    The line number is initialized in the insert method if the line number is = 0. This is ideally how you should do it.
     
    2: The tables in your application look to be heavily customized. I agree with Martin. If the first suggestion does not solve your issue, you must debug.
     
    An advice is also in order:
    It's a good idea to call the initValue method when you want to create a new record.https://gist.github.com/jofme/a7500b5d8f9dfde038bb18cad6259580#file-floodportglsystemjob-cs-L158
     
    EDIT: Without knowing the data you are posting, be careful when you post these journals manually. You will have missed lines since the job is not doing the inserts in a transaction, I.E it will not have rolled back if there is an error creating journal lines.

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
SajeedMullaji Profile Picture

SajeedMullaji 698

#2
Martin Dráb Profile Picture

Martin Dráb 327 Most Valuable Professional

#3
CU10121822-0 Profile Picture

CU10121822-0 320

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans