
Dear Readers,
Hope you are all safe and sound!
Let’s start with the article;
XMLports are used to export and import data between an external source and Dynamics 365 Business Central. Where we can easily map the tables and fields that are available in Business Central as well as the variables and constants to import/export data with XML format or any other format using the separator.
An XMLport is made up of the following Terms:
・An XMLport object
・An XMLport schema
・A Request page
・Properties, triggers, and code
XMLPorts object includes some basic properties which we can use like every objects in AL as below.
Format: Sets the formats of the source expression like Xml, VariableText, FixedText formats
Direction: Sets the XmlPort can be used to import data, export data, or import and export both. (Import, Export, Both)
TextEncoding: it is used to Specify the text encoding format to use when you use an XmlPort to export or import data as text. (MSDOS, UTF8, UTF16, WINDOWS)
UseRequestPage: Sets whether a request page is presented to the user. It is required when the user needs to filter the record.
TableSeparator: Specifies the table separator for a table.
The schema defines how the data will be extracted from or will be inserted into the Dynamics 365 Business Central database tables through an XMLport.
There are some specific nodes which we need to use to create XML schema as below:
You can use these nodes as nested nodes inside other nodes to define the structure of your XMLport schema.
Request pages will be prompted and we allow you to filter the data according to your requirement same as it’s in the Report request page but this page cannot be bookmarked by the user.
XMLport objects include triggers, methods, and properties which can be very useful to work with XMLPorts.
You can Find out more in detail about XMLports from Microsoft Docs.
Create new custom Tables for Hader and Line with list page, a card page And ListPart Page of Line.
Here to work with XMLPorts you can use the standard tables as well.
Create an object of XML port with the tables and fields available in business central.
XMLPort Code for Import and Export
Here is the AL code for XMLPort Object which I have created for my custom table.
In List Page Create two Action buttons to process Import and Export with the XMLPort which we created in the previous step.
Here I have added two actions on the List page to process import and export data with xml port as shown below with the correct parameters as per the requirement.
When You Click the Export. It will prompt a request page we can give the filters for which records we want to export And then Click Ok the XML File will be Downloaded with the filtered records which we specified.
Out Put: – Generated XML file
When You Click the Import. It will ask you to Select or Upload Your XML file. Then the Records that are available in your uploaded XML file will be Inserted in the Business Central table.
Upload The XML file with the exact format which we got in export file just the values of the fields will be changed As shown below
Out Put: – The record will be created in business central for the new data which we imported.
This is how the XML port is very useful to work with XML format or CSV format as well. It will directly import an export the data without the use of lengthy code of XMLBuffer.
We hope this write up will help you all!
Follow our page https://www.linkedin.com/company/madhda-business-solutions-pvt-ltd-mbs/mycompany/ to Stay connected with us to learn more!
For more details, pls visit our website www.madhda.com or contact us on sales@madhda.com
Thanks to all.
Madhda Team