XMLPorts Runner for Business Central SaaS
It’s possible to recall XMLPorts (Xmlport.Import and Xmlport.Export properties) using the STREAM objects (InStream and OutStream), in this way it is possible to pass the source files (input \ output) in the STREAMS and to pass it in execution to the XMLPort in order to be processed; very useful function for Dynamics 365 Business Central SaaS.
UPLOADINTOSTREAM and DOWNLOADFROMSTREAM
[Ok :=] UPLOADINTOSTREAM(DialogTitle, FromFolder, FromFilter, FromFile, NVInStream)
“Sends a file from Microsoft Dynamics NAV Server computer to the client computer.”
[Ok :=] DOWNLOADFROMSTREAM(VarInstream, DialogTitle, ToFolder, ToFilter, ToFile)
“Sends a file from the client computer to the corresponding Microsoft Dynamics NAV Server”

Procedures for STREAMS (for XMLPorts and Reports)
procedure RunXMLPortImport()
var
FileInstream: InStream;
FileName: Text;
begin
UploadIntoStream(”,”,”,FileName,FileInstream);
Xmlport.Import(Xmlport::MyXmlportImportCustomer,FileInStream);
Message(‘Import Done successfully.’);
end;
XMLPortExport
procedure RunXMLPortExport()
var
TempBlob: Record TempBlob;
FileName: Text;
MyOutStream: OutStream;
MyInStream: InStream;
outputFileName: Text;
begin
TempBlob.Blob.CREATEOUTSTREAM(MyOutStream);
Xmlport.Export(Xmlport::MyXmlportImportCustomer,MyOutStream);
TempBlob.Blob.CREATEINSTREAM(MyInStream);
outputFileName := ‘MyOutput.xml’;
DownloadFromStream(MyInStream,”,”,”,outputFileName); //Save in Download folder
Message(‘Export Done successfully.’);
end;
XMLPorts RUNNER – DEMO
I attached a code example (and an Ready-to-use APP) to launch XMLPorts from a page in a dynamic way, useful for Dynamics 365 Business Central SaaS.
Objects in APP:
- Page Pag50142.XMLPortsRunner (Page to launch XMLPorts with STREAMS)
- XMLPort Xml50140.InventoryItems (XMLPort to import Inventory Adjustements)


RUN
- Page XMLPorts – RUNNER



Source and APP in MyGitHUb page
https://github.com/rstefanetti/AL-Samples/tree/XMLPorts-Runner/XMLPorts%20Runner
Source https://robertostefanettinavblog.com/2019/01/03/xmlports-runner-for-business-central-saas/

Like
Report
*This post is locked for comments