RSS

XMLPort: Export from temporary tables

08 Aug

You can export data from tables to XML by using XMLPorts. But you can also use XMLPorts to export data from temporary tables.
The principle is to set the Temporary property on the table line and then create a function in XMLPort that inserts all the data into the temporary record.

I will start with creating a XMLPort to the Item table. I have only chosen two fields, “No.” and Description.

XMLPort

In order for the XMLPort to be temporary we have to set the following setting

Temporary Property on XMLPort

Lets create the function that inserts the data into the temporary table. Note that the record that I inserts to is the same record name on the XMLPort line.
Function that inserts the data into the temporary record

Once this is done I’ll create a test function that builds our temporary data, sends the data to the temporary XMLPort and then the export function on it.


    PROCEDURE ExportTempRecordsToXMLFile@1000000002();
    VAR
      TemporaryItemXMLPort@1000000003 : XMLport 69790;
      TempItem@1000000004 : TEMPORARY Record 27;
      TestFile@1000000002 : File;
      Outstream@1000000001 : OutStream;
      FileName@1000000000 : Text[100];
    BEGIN
      //Builds data in temporary records and uses a XMLport with the
      //temporary property to export the temporary records as XML

      //Build the temporary records
      //TempItem is declared as temporary
      TempItem.INIT;
      TempItem."No." := '1';
      TempItem.Description := 'Test1';
      TempItem.INSERT;

      TempItem.INIT;
      TempItem."No." := '2';
      TempItem.Description := 'Test2';
      TempItem.INSERT;

      //Create a stream to the destination file
      FileName := 'C:\temp\TESTXML.txt';
      TestFile.CREATE(FileName);
      TestFile.CREATEOUTSTREAM(Outstream);
      //XMLPort part
      TemporaryItemXMLPort.InsertTemporaryRecords(TempItem);
      TemporaryItemXMLPort.SETDESTINATION(Outstream);
      TemporaryItemXMLPort.EXPORT;

      TestFile.CLOSE;
      HYPERLINK(FileName); //To open the file when it is done
    END;

Once done the result is this

XMLPort export esult

 
1 Comment

Posted by on 2015-08-08 in Okategoriserade

 

Tags: , ,

One response to “XMLPort: Export from temporary tables

Leave a comment

 
Kauffmann @ Dynamics 365 Business Central

A good programmer makes all the right mistakes.

The BC Docs Librarian

Tips and news for AL programmers

Stefan Maroń

Dynamics 365 Business Central

James Pearson

Thoughts about Dynamics 365 Business Central, Git, Azure DevOps, PowerShell, Automated Testing, Visual Studio Code...and maybe some other stuff

Roberto Stefanetti BLOG

MVP & MCT Microsoft Dynamics 365 Business Central, Powershell, Azure, SQL Server

JoeBrown

DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Marije Brummel Blog | Business Central, Azure and more...

Design Patterns, Performance, Clean Code

Vjeko.com

Ideas in the cloud

Goprowe AB

Reflections from the ERP field

ArcherPoint

Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field