Skip to main content

Notifications

Announcements

No record found.

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
    SP-19090644-0 2 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
    EX-18092037-0 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
    YUN ZHU 75,673 Super User 2024 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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans