web
You’re offline. This is a read only version of the page.
close
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!
I have the same question (0)
  • 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
    89,830 Super User 2025 Season 2 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

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,899 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,444

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,304

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans