This week we are going to discuss how to use SmartConnect to post Sales Orders in Business Central. This functionality is available through the Business Central client, but not in the web services. The business logic used to batch post Sales transactions is stored in a Codeunit. This means we can use AL code to create a web service that calls the posting Codeunit.
*Note that any code provided is for use as a point of reference and will not be supported by eOne Solutions.
Creating the Service
Once the table is setup, we need to create a page that can be published as a web service. This page will be an API only page, because users have no reason to access this page through the Business Central client. This will be a simple page that SmartConnect will use to interact with the table we just created to post the batch.
Reporting and Security
All these options and settings are being imported to a Business Central table, therefore we can create a simple list page to allow users in Business Central to view previously posting settings used when posting through the API. In the example link I have created a simple example of a list page(50112) as a reference, and it can be expanded on as desired.
All AL Tables require a Permission Set to ensure access can be granted as needed. So, we will need to add a permission set to our extension in an XML file.
Once the extension is published, the web service will be automatically published. From within SmartConnect it will now be available as a destination. The mapping would look like the below screen shot. There are two options for ‘DocumentType’, Invoice and Order. In my example I used a source that contained the date ranges I wanted to use for posting. All of these can be set dynamically using calculated columns so the posting process would not require any manually processing.
GitHub repository with sample code.