Announcements
Hi,
You can achieve this by writing a codeunit.
Codeunit Example:
codeunit 50200 "Create Sales Order API"
{
Permissions = tabledata "Sales Header" = rimd, tabledata "Sales line" = rimd;
[ServiceEnabled]
procedure CreateSalesOrderFromPayload(payload: Text): Text;
var
JsonObject: JsonObject;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
SalesOrderLines: JsonArray;
SalesOrderLine: JsonToken;
JsonToken: JsonToken;
begin
JsonObject.ReadFrom(payload);
SalesHeader.Init();
if JsonObject.Get('orderDate', JsonToken) then
SalesHeader."Order Date" := JsonToken.AsValue().AsDate();
//Do same for all fields.
SalesHeader.Insert();
if JsonObject.Get('salesOrderLines', JsonToken) then begin
SalesOrderLines := JsonToken.AsArray();
foreach SalesOrderLine in SalesOrderLines do begin
SalesLine.Init();
SalesLine."Document Type" := SalesLine."Document Type"::Order;
SalesLine."Document No." := SalesHeader."No.";
if SalesOrderLine.AsObject().Get('description', JsonToken) then
SalesLine.Description := JsonToken.AsValue().AsText();
//Do same for all fields.
SalesLine.Insert();
end;
end;
end;
}
Postman Example:
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156