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

Post to Sales Header API Page - Document Date Over-ridden with Current Date

(0) ShareShare
ReportReport
Posted on by 20

Hi All

I am working on a solution for writing Sales/Purchase Documents from Excel into Business Central. I can create the Sales/Purchase Headers and their related Sales/Purchase Lines but I am finding that the Document Date that I sending to the API page is reverted to the current date when I look at the record in Sales Order/Invoices web page. It accepts the Posting Date and this appears in BC, it must be using the Excel uploaded Document Date because it calculates the Due Date correctly based on the Excel value but it writes the current date to the Document Date.

Looking at the Sale Header table definition I can see their is an InitRecord() procedure that sets the "Order Date" and "Document Date" to the WorkDate which makes me think that when the Sales Header is created, it defaults these dates to current date. Once the Sales Header is created, I can run a PATCH (update) on the record and change the Document Date and Due Date. I would like to avoid the two step process of inserting the headers and then updating just the dates, I have tried changing my Sales Header API page but I can't seem to find the pattern that will allow me to use the uploaded Document Date.

Any suggestions would be appreciate.

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    Are you feeding your API page with both the document date and the posting date or only the posting date.

    I suggest you fill in the posting date in your API. If you not fill in the posting date there is a risk that it will set the posting date = work date. And then the posting date will be evaluated and override the document date you are sending.

  • Suggested answer
    Vaishnavi J Profile Picture
    3,062 on at

    Hi,

    If you can create a webservices of the Purchase and Sales API V2 copy the same code from Microsoft Web Services and then modify it on document date section like below example.

           field("Document_Date"; Rec."Document Date")

                   {

                       Caption = 'Invoice Date';

                trigger OnValidate()

                       begin

                           RegisterFieldSet(Rec.FieldNo("Document Date"));

                           WORKDATE(Rec."Document Date"); // Gets and sets the work date for the current session.

                       end;

                   }

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much

  • Suggested answer
    Wyndows Profile Picture
    20 on at

    Thank you Vaishnavi

    Setting the WORKDATE() to the "Document Date" was what I need, I am not actually using the V2 API's, I am working directly with the Sales Header table using a PageType - API but the change below fixed the problem.

    field(documentDate; Rec."Document Date")
    {
    trigger OnValidate()
    begin

    WORKDATE(Rec."Document Date")

    end;

    With this change I can upload from Excel, multiple Sales Documents with headers and lines into BC and it will respect the Document Date on each header. Example below,


    }Sales-Orders-Writeback.jpg

  • Marco Mels Profile Picture
    on at

    Thank you for sharing.

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,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans