2

We are creating an Extension in AL to import orders. For this question we have simplified our extension to explain the challenges we are facing.

What we would like to do is import header + lines in Dynamics 365 Business Central.

To achive this we we have: - Created a table (Header) - Created a table (Lines) - Created a page of Type API (Doc) - Created a listPart (SalesLine)

Scenario 1

We have published page DOC and are trying to do a post request to this odata url.

POST https://api.businesscentral.dynamics.com/v1.0/{tennant}/Sandbox/ODataV4/Company('CRONUS%20NL')/Doc/ HTTP/1.1
Content-Type: application/json
Authorization: Basic {{username}} {{password}}

{
  "name": "Description",
  "SalesLines" : [{"lineno" : 1000}]
}

The response:

{
  "error": {
    "code": "BadRequest",
    "message": "Does not support untyped value in non-open type."
  }
}

Scenario 2

When we post:

POST https://api.businesscentral.dynamics.com/v1.0/3{tennant}/Sandbox/ODataV4/Company('CRONUS%20NL')/Doc/ HTTP/1.1
Content-Type: application/json
Authorization: Basic {{username}} {{password}}

{
  "name": "Description"
}

We get the following response:

{
  "@odata.context": "https://api.businesscentral.dynamics.com/v1.0/3ddcca3d-d343-4a06-95f9-f32dbf645199/Sandbox/ODataV4/$metadata#Company('CRONUS%20NL')/Doc/$entity",
  "@odata.etag": "W/\"JzQ0O3BKUzExSUMrQUl4UXFQc2R6V1J1ellvZEttRTJoa2xhanNtV0M0K3Ezajg9MTswMDsn\"",
  "id": 4,
  "name": "Description",
  "DateTime": "2019-05-20T19:33:13.73Z"
}

I have published our extension on GitHub Help would be appriciated.

gbierkens
  • 151
  • 6

1 Answers1

1

I have worked on a similar solution and found that the following things were required for it to work:

  1. The part containing your lines must be placed inside the repeater on your header Page.
  2. You must set the EntityName and EntitySetName on your part to the same values as on the actual page.
  3. When calling the API you must append the parameter $expand=[EntitySetName of your lines part] e.g $expand=orderLines.
  4. In the JSON body the property name of the array containing the lines must match the EntitySetName of the lines part.

I can provide some examples if the instructions above do not suffice.

kaspermoerch
  • 16,127
  • 4
  • 44
  • 67
  • 1
    Also, OData is case sensitive. From my experience Business Central defaults to a lower case initial character for subpart and disregarding what has been set in EntityName and EntitySetName which in this case would mean that "SalesLines" would become "salesLines". The best way to make sure which property names to use is to check the metadata. – theschitz Nov 25 '19 at 13:10