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 :
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)
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at
    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
  • EX-18092037-0 Profile Picture
    12 on at
    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!! 
  • SP-19090644-0 Profile Picture
    22 on at
    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! 

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans