D365 Business CentralConfigure Web Services through Code in Business Central
When coding an app that uses Webservices to connect to the integration solutions, it is generally recommended that there is a Setup, which we can configure, where the Webservices are created as well as deleted.
- Business Central
- VS Code with AL Language Extension
- Create a Setup Page having a boolean variable say ‘SetupExtension‘ and create a field having value as ‘SetupExtension Variable’.
- On the OnOpenPage trigger add a code to Check if Web Services are already created and accordingly set the ‘SetupExtension‘ boolean field.
Thus, whenever the Setup Page is Opened, the ‘SetupExtension‘ field is set as per the records in Web Services.
- On the OnQueryClosePage trigger write a code which will create the Web Services when ‘SetupExtension‘ boolean is set as ‘TRUE‘ and delete the Web Services if ‘SetupExtension‘ boolean is set as ‘FALSE‘.
i. When ‘SetupExtension‘ is set to ‘TRUE‘
New Webservices are created.
ii. When ‘SetupExtension‘ is set to ‘FALSE‘
Web Services are deleted.
Thus this way we can keep the existing app installed and enable/disable Web Services as needed. As compared to creating WebServices.xml file which directly creates the Web Services on installation of the app, I’ll be demonstrating it in my next blog.