web
You’re offline. This is a read only version of the page.
close
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;
}
I have the same question (0)
  • Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    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.

  • chigivigi Profile Picture
    77 on at

    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.

  • chigivigi Profile Picture
    77 on at

    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.

  • Verified answer
    Marco Mels Profile Picture
    on at

    Thank you for sharing final answser.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,151

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,443 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,092 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans