Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

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

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?
        
Categories:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,472 Super User 2024 Season 2 on at
    Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."
    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
  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,135 Super User 2024 Season 2 on at
    Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."
    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;
     
  • Jun Wang Profile Picture
    Jun Wang 7,443 Super User 2024 Season 2 on at
    Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."
    from function perspective, due day should be later or same as the ending date.
  • Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."
    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;
    }
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,472 Super User 2024 Season 2 on at
    Create Assembly header via API error: "Due Date is before Ending Date 02/13/24."
    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans