Hello, today I want to share a post related to how we could obtain any Business Central record in JSON format using a generic method that would be able to process any ERP Record/Table.
Project Overview
Video Demo
Video 1: Exporting the Item and Customer records in JSON format.
Video 2: Obtaining Record Item and Customer through Postman.
Business Central
Design
Below is the structure used to export a Record/Table in JSON format.
The idea was not only to export a JSON Key, Value, but also to add more information, such as the data type of each field, the company from which it was being exported, and its respective primary Key.
Codeunit
JSON Management V2
This codeunit is the brain/heart that allows us to convert any Record into JSON format.
DownloadJson
MyCustomAPI
For more information on how to use a web service with a codeunit I made a post some time ago with more details.
I also leave the official information from Microsoft.
Example:
PageExt
This is what our action/button would look like.
Clicking on the button:
This is how the Customer would look in JSON format:
Conclusion
Through this generic method of JSON format, we can convert any Business Central Record/Table that we want to be used by any external or internal application to the ERP.
Undoubtedly, this method could be improved or adapted to any need. For example, we could create a configuration table that allows us to select the fields that we want to export.
Code on GitHub
All the code used in this post can be found at the following link:
I hope this has been helpful.
Thanks, this is really awesome.
Thank you very much.
Great sample. Thanks for posting
Hello, thank you very much for your comment and reading my post. Kind regards.