Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Can't save document attachment while Sales-Post has an error

(1) ShareShare
ReportReport
Posted on by 12
Hi everyone 

I have a problem with saving the document attachment on Sales Header while posting the document. I saved 2 attachments to the Sales Header Attachment Factbox. I did this on event "OnRunOnBeforeFinalizePosting". If the posting flow doesn't have any error the attachment are successfully saved on the Sales Invoice Heard table, but if any errors happen during the posting flow the Sales Header is reopened again but the attachments are deleted and I want the attachments to be saved when Sales Header is reopened. I also used the Commit method but if I use Commit the document will be posted even if it has any errors.

So what I want is to prevent document from being posted if while the process any errors occurs and my attachments to be saved to Sales Header attachment document.

Can anyone help with this? Thanks in advance!
  • SP-19090644-0 Profile Picture
    10 on at
    Can't save document attachment while Sales-Post has an error
    Hi Zhu,

    Thanks for your answer. The function that I use to save the attachments works correctly when the posting flow doesn't have any error and the attachments are successfully attached to Sales Invoice Header. The problem is that when an error occurs while posting flow and everything rolls-back my attachments are not saved to the Sales Header attachment document. I also used the Commit method but if I use Commit the document will be posted even if it has any errors.

    What I want is to prevent document from being posted if while the process any errors occurs and my attachments to be saved to Sales Header attachment document.

    Thanks in advance! 
  • EX-18092037-0 Profile Picture
    12 on at
    Can't save document attachment while Sales-Post has an error
    Hi Zhu,
    Thanks for your answer! The problem is that my function that saves the attachments works correctly when it has not any error during the posting flow, but if an error occurs while posting the Sales Header everything rolls back and the attachments are not saved.
    I also used Commit method. The attachments are saved but also the document is posted even though it has an error.
    What I want is to save the attachments, but to prevent the document from being posted. Thanks in advance!! 
  • Suggested answer
    YUN ZHU Profile Picture
    86,202 Super User 2025 Season 1 on at
    Can't save document attachment while Sales-Post has an error
    Although I personally don't recommend it, you can add a Database.Commit() Method
     
    But when you post for the second time or later, you need to determine whether the attachment already exists.
    Alternatively, there is actually a standard function that you can use, and you only need to click on it.
    Dynamics 365 Business Central: Automatically attaching as PDF to posted sales invoice (Document Attachment)
     
    Hope this helps.
    Thanks
    ZHU

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans