I try to create web api extension with 2 page in Ms Dynamic 365 BC. my goal is create api like sales order which is can insert sales order header and sales order line in one post, below are my AL code.
page 50103 ScannedShipmentMstEntity { PageType = API; Caption = 'ScannedShipmentMstEntity'; EntityName = 'ScannedShipmentMst'; EntitySetName = 'ScannedShipmentMsts'; SourceTable = ScannedShipmentMst; DelayedInsert = true; ODataKeyFields = id; UsageCategory = Lists; layout { area(Content) { repeater(General) { field(id; id) { Caption = 'id'; ApplicationArea = All; } field(header; header) { Caption = 'Header'; ApplicationArea = All; } part(ScannedShipmentDataEntity; ScannedShipmentDataEntity) { ApplicationArea = All; Caption = 'Lines', Locked = true; EntityName = 'ScannedShipmentDataEntity'; EntitySetName = 'ScannedShipmentDataEntities'; SubPageLink = BatchId = FIELD (header); } } } } trigger OnInsertRecord(BelowxRec: Boolean): Boolean begin Insert(true); exit(false); end; trigger OnDeleteRecord(): Boolean begin Delete(true); end; }
page 50101 ScannedShipmentDataEntity { Caption = 'ScannedShipmentDataEntity'; DelayedInsert = true; PageType = ListPart; SourceTable = ScannedShipmentData; SourceTableTemporary = true; layout { area(Content) { repeater(General) { field(id; id) { Caption = 'Id'; ApplicationArea = All; } field(Transdate; Transdate) { Caption = 'Transdate'; ApplicationArea = All; } field(OrderNum; OrderNum) { Caption = 'OrderNum'; ApplicationArea = All; } field(OrderLine; OrderLine) { Caption = 'OrderLine'; ApplicationArea = All; } field(item; item) { Caption = 'item'; ApplicationArea = All; } field(Desc; Desc) { Caption = 'Desc'; ApplicationArea = All; } field(um; um) { Caption = 'um'; ApplicationArea = All; } field(ShipQty; ShipQty) { Caption = 'ShipQty'; ApplicationArea = All; } field(ScanQty; ScanQty) { Caption = 'ScanQty'; ApplicationArea = All; } field(ScanBox; ScanBox) { Caption = 'ScanBox'; ApplicationArea = All; } field(BatchId; BatchId) { ApplicationArea = All; Caption = 'BatchId'; } } } } trigger OnInsertRecord(BelowxRec: Boolean): Boolean begin Insert(true); exit(false); end; trigger OnDeleteRecord(): Boolean begin Delete(true); end; }
but when i try to post it in postman with body
{
"header" : "Test2",
"scannedShipmentDataEntities" :[
{
"OrderNum": "C9",
"OrderLine": 1,
"item": "Item 1",
"um": "KG",
"ShipQty": 200
},
{
"OrderNum": "C8",
"OrderLine": 2,
"item": "Item 2",
"um": "KG",
"ShipQty": 200
}
]
}
and the response
{
"@odata.context": "webapiurl/api/beta/$metadata#scannedShipmentMsts/$entity",
"@odata.etag": "W/\"JzQ0O1pJZWY3RlpOUmo3MHBXZTkzQkUwWlpzcXM0UkdqSjBDNithYnBES3pYQWc9MTswMDsn\"",
"id": "d605d939-7c57-4e7a-9313-1f589d129759",
"header": "Test2"
}
then run Get request to see the result
{{WebAPIUrl}}/scannedShipmentMsts(d605d939-7c57-4e7a-9313-1f589d129759)?$expand=scannedShipmentDataEntities
and the response
{
"@odata.context": "webapiurl/api/beta/$metadata#scannedShipmentMsts/$entity",
"@odata.etag": "W/\"JzQ0O1pJZWY3RlpOUmo3MHBXZTkzQkUwWlpzcXM0UkdqSjBDNithYnBES3pYQWc9MTswMDsn\"",
"id": "d605d939-7c57-4e7a-9313-1f589d129759",
"header": "Test2",
"scannedShipmentDataEntities": []
}
looks like only header can be saved but not the line.
Is there any step that i miss? please your suggestion to solve this problem.
Thank You