For Custom API development, we can add another page as part of the main API page.
This results in nested records.... nice
The downside is that we cannot always define a table relation for the subpage. Relations should often be defined with calculated values from the retrieved main record.
An example from our business scenario:
We need to give address information in a nested json for our warehouse api.
When the Source Document Type is a Purchase Order, we'll retrieve the information from the Purchase Order.
When the Source Document Type a Sales Return Order, we need to retrieve the information from the Sales Return Order.
When the Source Document Type is a Transfer Order, we need to retrieve the information from the Transfer Order.
The only solution now is to create 3 different API pages and fill them accordingly the Source Document Type
It would be nice if we can just Fill a JsonObject variable and assign this to the API Page as a field
page 50000 "PTE_My Custom API"
{
PageType = API;
layout
{
area(content)
{
repeater(General)
{
field(sourceDocumentType; "Source Document Type")
{
ApplicationArea = All;
}
field(sourceDocumentNo; "Source Document No.")
{
ApplicationArea = All;
}
field(addressInfo; AddressInfoObject)
{
ApplicationArea = All;
}
}
}
}
....
local procedure FillAddressJSON(AddressName: Text; AddressStreet: Text; AddressCity: Text; AddressState: Text; AddressCountryCode: Text; AddressPostalCode: Text)
begin
Clear(AddressInfoObject);
AddressInfoObject.Add('name', AddressName);
AddressInfoObject.Add('street', AddressStreet);
AddressInfoObject.Add('city', AddressCity);
AddressInfoObject.Add('state', AddressState);
AddressInfoObject.Add('countryCode', AddressCountryCode);
AddressInfoObject.Add('postalCode', AddressPostalCode);
if not AddressInfoObject.WriteTo(JSON) then
Clear(JSON);
end;
var
AddressInfoObject: JsonObject;
}
Business Central Team (administrator)
Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team