RE: Cannot create a record in Expense lines. The record already exists.
Hello,
Hope you are doing well. Just wondering whether you have made some progress here and have been able to resolve the issue.
Have you had the chance to debug the insert method of TrvExpTrans as per Nikolaos suggestion?
Also, I have done a research on this topic and I found a similar issue caused by duplicate Expense Transaction Number (not to be confused with expense report number). ExpenseTransaction number (TrvExpTrans.ExpTransNumber) is unique for every expense transaction line, somehow the number sequence got corrupted on that specific case and caused the error message – “Cannot create a record in Expense lines (trvExpTrans). The record already exists”.
You can verify on a test environment by changing the Number Sequence for the Expense Transaction Number. Below is a screenshot from standard environment. The recommendation is to change the format to LEGALENTY_SOMECONSTANT_########### so that it doesn't overlap with current number sequence. Also, it would be good if you stop the auto-cleanup.

If this is not the same case, I would encourage you to log a new service request to Microsoft support so we can review the reported issue and further investigate it.
Thank you,