Using OdataKeyFields for fetching records in Business Central Web Services

Introduction:

Business Central provides us with Web Services which we can use for CRUD operations on specific tables. However it also provides us with different methods of accessing specific records for CRUD operations.

Pre-requisites:

Business Central On-Premise or OnCloud.

References:

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-odatakeyfields-property

Usage:

In Business Central, if we do not specify the ODataKeyFields as a property on the Page that we’ll be using as Web Service, then by default we have to use the Primary Key.

However if we specify the “ODataKeyFields” in the page, we can use the field we have specified as the key for pulling the record in Web Services.

While there are no limitations on which field can be used as key field, keep in mind that Business Central fetches the first record matching that field.

For instance if you use the “Buy-from Vendor No.” as the ODataKeyField, then the Web Service will fetch the first matching record sorted by the Primary Key.

Standard Business Central APIs use the “SystemId” field as the ODataKey field.

You can also use multiple Keys in ODataKeyFields and use them for fetching records.

Conclusion:

Thus, we saw how we can use ODataKeyFields property for fetching records and performing CRUD operations. As a side note, you can also use multiple keys in ODataKeyFields.


Share Story :