When developing API pages that accommodate for a subpage with a SubPageLink, it is very important to know that different behaviors might occur at runtime, depending on Dynamics 365 Business Central version.
Let’s say that you have an API called italianWines bounded to wine entity with a subpage glassTypes that is linked using the field “Standard Glass Type”.
You could then send a GET like
chucknorris:7048/.../italianWines
to list all the italian wines in the specific company.
Now, you cold try to view the standard glass types by adding the $expand parameter like
chucknorris:7048/.../italianWines$expand=glassTypes
Everything works fine… as long as “Standard Glass Type” is part of the main page.
But what would happen if the linked field, Standard Glass Type, is not part of the main page?
The behavior is different depending on Dynamics 365 Business Central version
Runtime versions up to and included 16.6
An HTTP 500 Error is thrown like the one below
The error is as per the following:
{
"error": {
"code": "Unknown",
"message": "Sequence contains no matching element. CorrelationId: a4aea12d-23d1-4028-bbcc-bad4e80a382e."
}
}
SOLUTION: Add the field to the main page
Runtime versions 16.7 and higher for 16.x, and 17.0
An HTTP 501 not Implemented code will be thrown, instead of a generic HTTP 500 exception, if the linked field is not populated in the main page but is linked via a SubPageLink. This will pinpoint which table field missing is causing the request to fail in order to have this added as part of the main page.
The error is similar to the following:
{
"error": {
"code": "BadRequest_MethodNotImplemented",
"message": "The table field with id no. '9' is missing in the parent API page with entity name 'wine'. CorrelationId: 8f5f9537-96ab-480c-8262-54fe6b145185."
}
}
SOLUTION: Add the field to the main page
Runtime versions 17.1 and higher for 17.x
It would work as expected and expand glassTypes.