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...
Answered

Custom Page Type API AL extension updating fields

(0) ShareShare
ReportReport
Posted on by 77

I made a new API extension in which I would update a DateTime field, Shipment Date, in my Sales Invoice record. I placed an oninsert trigger where the date would be updated and later displayed as a message but the action is not being trigger and the page is bank when i visit it in Business Central.

This is my code:

page 50105 "Custom Invoice API"
{
    PageType = API;
    Caption = 'Custom Sales Invoice Header API';
    APIPublisher = 'xy';
    APIVersion = 'beta';
    APIGroup = 'customsalesinvoiceheader';
    EntityName = 'customsalesInvoiceHeader';
    EntitySetName = 'customsalesInvoiceHeaders';
    SourceTable = "Sales Invoice Header";
    DelayedInsert = true;
    ODataKeyFields = "Shipment Date";


    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(id; "No.")
                {
                    Caption = 'No.';
                }
                field(name; "Sell-to Customer Name")
                {
                    Caption = 'Customer Name';
                }
                field(address; "Sell-to Address")
                {
                    Caption = 'Sell-to Adress';
                }
                field(shipdate; "Shipment Date")
                {
                    Caption = 'Shipment Date';
                }
            }
        }
    }
    var
        message: Text;

    trigger OnInsertRecord(BelowxRec: Boolean)Boolean
    begin
        message := readInvoice();
        Message(message);
        updateInvoice();
        exit(true);
    end;

    procedure readInvoice()Text
    var
        currentInvoice: Record "Sales Invoice Header";
    begin
        exit(currentInvoice."No." + ' ' + currentInvoice."Sell-to Customer Name" + ' ' + currentInvoice."Sell-to Address" + ' ' + Format(currentInvoice."Shipment Date"));
    end;

    procedure updateInvoice()
    var
        currentInvoice: Record "Sales Invoice Header";
    begin
        currentInvoice."Shipment Date" := DMY2Date(1962020);
    end;
}
  • Verified answer
    Marco Mels Profile Picture
    on at
    RE: Custom Page Type API AL extension updating fields

    Thank you for sharing final answser.

  • chigivigi Profile Picture
    77 on at
    RE: Custom Page Type API AL extension updating fields

    I solved my issue. I changed my url from api.businesscentral.dynamics.com/v1.0 to api.businesscentral.dynamics.com/v2.0

    After that I was able to make a get request using the API url.

  • chigivigi Profile Picture
    77 on at
    RE: Custom Page Type API AL extension updating fields

    I have updated my code and now it looks like this:

    page 50105 "Custom API"

    {

       PageType = API;

       Caption = 'Custom Sales Header API';

       APIPublisher = 'name';

       APIVersion = 'v1.0';

       APIGroup = 'group';

       EntityName = 'SalesHeader';

       EntitySetName = 'SalesHeaders';

       SourceTable = "Sales Header";

       DelayedInsert = true;

       ModifyAllowed = true;

       DeleteAllowed = true;

       ODataKeyFields = SystemId;

       layout

       {

           area(Content)

           {

               repeater(GroupName)

               {

                   field("No"; "No.")

                   {

                       Caption = 'No.';

                       ApplicationArea = All;

                   }

                   field("SelltoCustomerName"; "Sell-to Customer Name")

                   {

                       Caption = 'Customer Name';

                       ApplicationArea = All;

                   }

                   field("ShiptoAddress"; "Ship-to Address")

                   {

                       Caption = 'Sell-to Adress';

                       ApplicationArea = All;

                   }

                   field("ShipmentDate"; "Shipment Date")

                   {

                       Caption = 'Shipment Date';

                       ApplicationArea = All;

                   }

                   field(SystemId; SystemId)

                   {

                       Caption = 'Shipment Date';

                       ApplicationArea = All;

                   }

               }

           }

       }

       trigger OnInsertRecord(BelowxRec: Boolean): Boolean

       begin

           Insert(true);

           Modify(true);

           exit(true);

       end;

       trigger OnModifyRecord(): Boolean

       var

           SalesHeader: Record "Sales Header";

       begin

           SalesHeader.SetRange(SystemId, SystemId);

           SalesHeader.FindFirst();

           If "Shipment Date" <> SalesHeader."Shipment Date" then begin

               SalesHeader.TransferFields(rec, false);

               SalesHeader.Rename("Shipment Date");

               TransferFields(SalesHeader);

           end;

       end;

       trigger OnDeleteRecord(): Boolean

       begin

           Delete(true);

       end;

    }

    I am having trouble visiting my API using this url:

    api.businesscentral.dynamics.com/.../<sandbox tenant id>/sandbox/api/<ApiPublisher>/<ApiGroup>/<ApiVersion>

    I am getting RequestDataInvalid error back in xml response.

  • Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Custom Page Type API AL extension updating fields

    Here you're working on a different variable (currentInvoice) that not contains your current posted invoice.

    Why you're not using simply Rec? Rec is the currently posted record from your API.

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 594 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 463

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 391

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans