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, ...
Answered

Error while posting pending Invoice in X++

(3) ShareShare
ReportReport
Posted on by 666

Hi,

I am encountering an error while posting a pending invoice using X++. I have a custom development where the user can post an invoice without a product receipt.

When I trigger invoice posting through my custom Post button, I create a pending invoice and use the below standard code to post it. However, I receive the following error on the first attempt:

"Cannot edit a record in Posted vendor invoice lines (VendInvoiceTrans). Update must be performed inside a transaction."

On the second attempt, the invoice posts successfully.

purchFormLetter.purchSelectLines(purchTableSet, purchLineSet, vendInvoiceInfoTable);

if (purchFormLetter.validate())
{
purchFormLetter.reArrangeNow(false);
purchFormLetter.run();
}

 

Could you please advise on how to resolve this issue?

I have the same question (0)
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Saalim,

    You need to put your logic between ttsbegin and ttscommit
     

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future.

  • Raj Borad Profile Picture
    1,428 on at
    Hi,
     
    F&O requires data updates to be wrapped in a transaction context to maintain consistency. 
    As Layan suggests, To resolve this, wrap your logic inside a 'ttsBegin' / 'ttsCommit' block before calling '.run()'. 
     
    However, be cautious—'purchFormLetter.run()' internally manages transactions, so wrapping only the preparation steps inside 'ttsBegin/ttsCommit' is preferred. Also ensure no other background process or asynchronous operation interferes between these attempts.
     
    Do have any custom logic works during '.run()' execution?
     
  • Saalim Ansari Profile Picture
    666 on at
    Hii Layan and Raj 
    I tried the same approach, but it didn’t work for me initially. However, when I switched to a different server, it worked fine.
     
    Thanks,
    Saalim Ansari
  • Saalim Ansari Profile Picture
    666 on at
    Hello @Layan Jwei and @Raj Borad

    I tried the same approach as discussed earlier. Initially, it didn’t work for me, but when I switched to a different server, it worked fine.

    However, I’m facing the same issue again. This time, I’ve used the exact code you both suggested, but the error has reappeared.

    Let me know if you have any further suggestions.

  • Raj Borad Profile Picture
    1,428 on at
    Hi Saalim,
     
    Can you please share the updated code which you are currently using and facing the error? 
    As you said, It works fine in other instance. Does that is currently working or also facing error there?
  • Verified answer
    Saalim Ansari Profile Picture
    666 on at

    Hello @Layan Jwei and @Raj Borad

    The suggested approach worked for some items but not for others. For example:

    • It worked fine for Item ID: A0001

    • But failed for Item ID: B0001, showing the same posting error again.

    The code and logic are exactly the same in both cases. This leads me to think it might be related to some item-specific configuration—maybe related to tracking dimensions like batch/serial or inventory setup.

     

    Please advise if there's anything else I should check from the item master or setup side.

    Thanks again for your support!

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 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans