XMLPorts Runner for Business Central SaaS
i found this nice question on MS Community : “XML port and file Output” in BC SaaS https://community.dynamics.com/business/f/758/t/298825
“If you are working on the Business Central SaaS you cannot specify a network folder because the cloud doesn’t know that; In the cloud, you cannot automatically save a file in a local folder. What you can do is using a Cloud Storage provider and having a “shared folder” with an URL (for example, Onedrive).”
Other Solution\Workaround
In this case is 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
I am using DownloadFromStream(MyInStream,”,”,”,outputFileName); function in AL to download file but it ask me to save the file but I want to save my file automatically in the specifically one folder.
Please give me suggestion for that.
Similar to Sandip – I have an .al extension running a DownloadFromStream command, but I cannot seem to suppress the dialog box? I have populated both the ToFolder and OutputFilename parameters, but it still wants to bring up a dialog.
I need to run this on a schedule, so I can’t have a dialog.