How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?

  • How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?

    Posted by DSC Communities on January 8, 2023 at 7:26 pm

    How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?
    Follow
    Wolter Kaper
    Wolter KaperJan 08, 2023 11:07 AM
    #Technical #D365BusinessCentral #ArchitectureandDevelopment #Beginner ​​​​Dear BC experts, When …

    1. How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?

    Wolter Kaper
    Posted Jan 08, 2023 11:07 AM
    #Technical #D365BusinessCentral #ArchitectureandDevelopment #Beginner
    ​​​​Dear BC experts,

    When using event subscriptions to customize the posting of a sales order, how do you react to errors that may occur in Microsofts part of the code? How do you “catch” and react to such errors?

    Simple usecase: When a sales order gets posted, I want to update the “posting date” to today, but only if the posting of the Sales Order succeeds.
    I suppose I can use the ‘OnBeforePostSalesOrder’ event.
    Using ‘OnAfterPostSalesOrder’ would be too late, the order would get posted carrying the old value of the Posting Date.
    However when I update the posting date field using the ‘OnBeforePostSalesOrder’ event then I cannot yet know if the posting is going to succeed. One of the checks that Microsoft does may result in an error: in that case I want to roll back the change made in the Sales Header.
    (Note that the error could be about posting one of the lines, not necessarily the Sales Header).
    If I found an “OnPostingError” event in “Sales Post” codeunit 80 then I think this would solve my problem, but such an event does not seem to exist.
    How can I achieve the conditional update?

    Any help appreciated.

    With best regards,
    Wolter

    ——————————
    Wolter Kaper
    Entocare C.V.
    Wageningen
    ——————————

    2. RE: How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?
    NAVUG ALL STAR
    Kim Dallefeld
    Posted Jan 23, 2023 09:51 AM
    I have years in NAV mostly functional, though I am a certified developer. Unless you are using a Commit Statement when you change the posting date, any Microsoft error will rollback to the unposted state. And, by the way, you should almost never use a Commit.
    On another note, you should train users to change their posting date and to control the posting date, someone can set the Allow Posting From date to today’s date each morning thus making sure posting is not being done to prior dates. Thus no need for your customization.

    ——————————
    Kim Dallefeld, MVP, MCT Kim@Dallefeld.com
    CEO/Principal Consultant
    Dallefeld Consulting, LLC

    NAVUG Legend
    NAVUG All-Star
    NAVUG Board and Programming Committee
    ——————————

     

    3. RE: How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?
    TOP CONTRIBUTOR
    Andrew Good
    Posted Jan 24, 2023 07:54 AM
    Further to Kim’s comments, you have clearly identified base BC behavior with the Posting Date. Since it sounds like you always want to update the posting date to “today” during posting except if the posting fails. I would suggest that you activate the Change Log on the Sales Order Header Posting Date field, so you have a record of the various values used for the order and you always change the posting date using ‘BeforePostSalesOrder’. Alternately you could save the Posting Date from ‘OnBeforePostSalesOrder’ and reset it if the posting fails.

    ——————————
    Andrew Good
    President
    Liberty Grove Software
    Oakbrook Terrace IL
    ——————————

    replied 12 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘How to customise Sales Order posting and react to user errors caught in Microsoft’s parts of the code?’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for people  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!