web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."

(1) ShareShare
ReportReport
Posted on by 5
I want to create Assembly header via BC364 API, so i wrote this AL extension:
 
page 50132 CustomAssemblyHeader
{
    PageType = API;
    APIVersion = 'v2.0';
    APIPublisher = 'streamline';
    APIGroup = 'export';
    EntityName = 'assemblyHeader';
    EntitySetName = 'assemblyHeaders';
    ODataKeyFields = SystemId;
    SourceTable = /Assembly Header/;
    DelayedInsert = true;
    layout
    {
        area(Content)
        {
            repeater(Group)
            {
                field(id; Rec.SystemId)
                {
                    Caption = 'id';
                }
                field(documentType; Rec./Document Type/)
                {
                    Caption = 'documentType';
                }
                field(item; Rec./Item No./)
                {
                    Caption = 'item';
                }
                field(qty; Rec.Quantity)
                {
                    Caption = 'qty';
                }
                field(location; Rec./Location Code/)
                {
                    Caption = 'qty';
                }
            }
        }
    }
}
 
app.json
{
  /id/: /d0e31363-2e61-4e64-jsbf-fe2bb22e84354/,
  /name/: /name/,
  /publisher/: //,
  /version/: /2.0.0.3/,
  /brief/: //,
  /description/: //,
  /privacyStatement/: //,
  /EULA/: //,
  /help/: //,
  /url/: //,
  /logo/: //,
  /dependencies/: [],
  /screenshots/: [],
  /platform/: /1.0.0.0/,
  /application/: /17.0.0.0/,
  /idRanges/: [
    {
      /from/: 50090,
      /to/: 50149
    }
  ],
  /contextSensitiveHelpUrl/: https://Extention2020wave2.com/help//,
  /showMyCode/: true,
  /runtime/: /7.0/
}
 
To create a new record i perform this request via Postman:
POST https:/api.businesscentral.dynamics.com/v2.0/tenantId/Sandbox2/api/streamline/export/v2.0/companies(0dd10330-db46-ee11-be72-6045bdac9e37)/assemblyHeaders
Body:
{
    /documentType/: /1/,
    /item/: /1969-W/,
    /qty/: 2,
    /location/: /GREEN/
}
Response:
{
    /error/: {
        /code/: /Application_DialogException/,
        /message/: /Due Date  is before Ending Date 02/13/24.  CorrelationId:  a26bd40a-97a2-48f1-ad6e-095267a90331./
    }
}
 
Than i add dates into my page:
page 50132 CustomAssemblyHeader
{
    PageType = API;
    APIVersion = 'v2.0';
    APIPublisher = 'streamline';
    APIGroup = 'export';
    EntityName = 'assemblyHeader';
    EntitySetName = 'assemblyHeaders';
    ODataKeyFields = SystemId;
    SourceTable = /Assembly Header/;
    DelayedInsert = true;
    layout
    {
        area(Content)
        {
            repeater(Group)
            {
                field(id; Rec.SystemId)
                {
                    Caption = 'id';
                }
                field(documentType; Rec./Document Type/)
                {
                    Caption = 'documentType';
                }
                field(item; Rec./Item No./)
                {
                    Caption = 'item';
                }
                field(qty; Rec.Quantity)
                {
                    Caption = 'qty';
                }
                field(location; Rec./Location Code/)
                {
                    Caption = 'qty';
                }
                field(dueDate; Rec./Due Date/)
                {
                    Caption = 'dueDate';
                }
                field(endDate; Rec./Ending Date/)
                {
                    Caption = 'endDate';
                }
            }
        }
    }
}
 
And change request body:
{
    /documentType/: /1/,
    /item/: /1969-W/,
    /qty/: 2,
    /location/: /GREEN/,
    /dueDate/: /2024-02-14/,
    /endDate/: /2024-02-13/
}
 
But i still have the same error:
{
    /error/: {
        /code/: /Application_DialogException/,
        /message/: /Due Date  is before Ending Date 02/13/24.  CorrelationId:  a26bd40a-97a2-48f1-ad6e-095267a90331./
    }
}
 
I think that error is because Due Date is empty and less than Ending Date which somehow is equal to 2024-02-13.
I also found out in source code that error occurred in OnValidate() trigger in /Due date/ field of /Assembly Header/ table:
field(24; /Due Date/; Date)
{
    Caption = 'Due Date';
    trigger OnValidate()
    begin
        ValidateDueDate(/Due Date/, true);
    end;
}
 
And inside ValidateDueDate and ValidateDates funstions i found this dates checks:
if /Due Date/ < /Ending Date/ then
    Error(Text015, FieldCaption(/Due Date/), /Due Date/, FieldCaption(/Ending Date/), /Ending Date/);
if /Ending Date/ < /Starting Date/ then
    Error(Text015, FieldCaption(/Ending Date/), /Ending Date/, FieldCaption(/Starting Date/), /Starting Date/);
    
How can i solve this problem?
        
  • Suggested answer
    YUN ZHU Profile Picture
    103,216 Super User 2026 Season 2 on at
    Hi, this is standard behavior. Due Date will be recalculated in fields such as "Item No.", "Location Code", and "Variant Code".
    The easiest way to deal with this problem is to skip this error. . For example, you can subscribe to the following event and set IsHandled:=True, which should solve this problem.
     
    Hope this helps.
    Thanks.
    ZHU
  • OH-27040836-0 Profile Picture
    5 on at
    Thank you very much for your answer.
    I subscribed to the event and this helped get rid of the previous error. However, a new error has appeared that cannot be traced. I can't find any date calculations so that dates are uninitialized.
     
    codeunit 50101 MySubscribers
    {
        EventSubscriberInstance = StaticAutomatic;
     
        [EventSubscriber(ObjectType::Table, Database::"Assembly Header", 'OnBeforeValidateDates', '', true, true)]
        local procedure SkipOnBeforeValidateDates(var AssemblyHeader: Record "Assembly Header"; FieldNumToCalculateFrom: Integer; var DoNotValidateButJustAssign: Boolean; var IsHandled: Boolean)
        begin
            IsHandled := true;
        end;
    }
     
    Error:
    {
        "error": {
            "code": "Unknown",
            "message": "You cannot base a date calculation on an undefined date.\r\n\r\nDate: 0D\r\nFormula: 90D.  CorrelationId:  5d3dff91-2239-47c8-b3cc-38f8094bf362."
        }
    }
     
    I also tried to initialize the dates manually with WorkDate() or Today, but that didn't help.
    codeunit 50101 MySubscribers
    {
        EventSubscriberInstance = StaticAutomatic;
     
        [EventSubscriber(ObjectType::Table, Database::"Assembly Header", 'OnBeforeValidateDates', '', true, true)]
        local procedure SkipOnBeforeValidateDates(var AssemblyHeader: Record "Assembly Header"; FieldNumToCalculateFrom: Integer; var DoNotValidateButJustAssign: Boolean; var IsHandled: Boolean)
        begin
            AssemblyHeader."Due Date" := WorkDate();
            AssemblyHeader."Ending Date" := WorkDate();
            AssemblyHeader."Starting Date" := WorkDate();
            AssemblyHeader."Posting Date" := WorkDate();
            IsHandled := true;
        end;
    }
  • Jun Wang Profile Picture
    8,220 Moderator on at
    from function perspective, due day should be later or same as the ending date.
  • Suggested answer
    Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at
    Please create a separate table with those fields and use it as Source table of the API
    Then try to insert the data to Assembly Header using OnInsert trigger
     
      trigger OnInsertRecord(BelowxRec: Boolean): Boolean
        var
            AssemblyHeader: Record "Assembly Header";
        begin
            AssemblyHeader.Init();
            AssemblyHeader.Validate("Document Type", Rec."Document Type");
            AssemblyHeader.Insert(true);
            AssemblyHeader.Validate("Item No.", Rec."Item No.");
            AssemblyHeader.Validate("Quantity", Rec.Quantity);
            AssemblyHeader.Validate("Location Code", Rec."Location Code");
            AssemblyHeader.Modify(true);
        end;
     
  • Suggested answer
    YUN ZHU Profile Picture
    103,216 Super User 2026 Season 2 on at
    Hi, It may be that this part is not executed. I suggest you investigate this part of the standard code and see if you can customize this part of the code into this subscription event.
     
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 755 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 413 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 387 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans