Skip to main content

Notifications

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.

  • Marco Mels Profile Picture
    on at
    RE: Post to Sales Header API Page - Document Date Over-ridden with Current Date

    Thank you for sharing.

  • Suggested answer
    Wyndows Profile Picture
    20 on at
    RE: Post to Sales Header API Page - Document Date Over-ridden with Current Date

    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

  • Suggested answer
    Vaishnavi J Profile Picture
    3,058 on at
    RE: Post to Sales Header API Page - Document Date Over-ridden with Current Date

    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
    Inge M. Bruvik Profile Picture
    1,021 Moderator on at
    RE: Post to Sales Header API Page - Document Date Over-ridden with Current Date

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,190 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans