Announcements
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.
Thank you for sharing.
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,
}
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
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.
André Arnaud de Cal...
294,190
Super User 2025 Season 1
Martin Dráb
232,968
Most Valuable Professional
nmaenpaa
101,158
Moderator