RSS

XMLPort: Import Into Temporary Table

08 Aug

Earlier today I wrote a blog post XMLPort: Export from temporary tables. The principle is the same when you want to import to a temporary table. Instead of calling a function in XMLPort before you call the export that inserts values into the temporary table you do the opposite, call a function after the import has completed that copies all the temporary data to your temporary record parameter.  Create the XMLPort in the same way and don’t forget to mark the table as temporary.

Temporary Property on XMLPort

Create a function in the XMLPort that fetches the imported data and copies it to the parameter.

    PROCEDURE GetTemporaryRecord@1000000002(VAR TemporaryItem@1000000000 : Record 27);
    BEGIN
      //Copy all the temporary records to the new temporary variable
      IF Item.FINDSET THEN REPEAT
        TemporaryItem := Item;
        TemporaryItem.INSERT;
      UNTIL Item.NEXT = 0;
    END;

Here is the test function that I use to call the XMLPort.

PROCEDURE ImportXMLToTempRecords@1000000013();
    VAR
      TemporaryItemXMLPort@1000000003 : XMLport 69782;
      TempItem@1000000004 : TEMPORARY Record 27;
      TestFile@1000000002 : File;
      Instream@1000000001 : InStream;
      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

      FileName := 'C:\temp\TESTXML.txt';
      TestFile.OPEN(FileName);
      TestFile.CREATEINSTREAM(Instream);
      TemporaryItemXMLPort.SETSOURCE(Instream);
      TemporaryItemXMLPort.IMPORT;
      TemporaryItemXMLPort.GetTemporaryRecord(TempItem);
      TestFile.CLOSE;

      IF TempItem.FINDSET THEN
        MESSAGE('Found the imported records, count=%1',TempItem.count)
      ELSE
        ERROR('Couldn't find the imported records');
    END;

Here is the XML that I’m importing (export from my previous blog post)

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<NAVItems>
 <NAVItem>
  <No>1</No>
  <Description>Test1</Description>
 </NAVItem>
 <NAVItem>
  <No>2</No>
  <Description>Test2</Description>
 </NAVItem>
</NAVItems>
 
1 Comment

Posted by on 2015-08-08 in Okategoriserade

 

Tags: , , ,

One response to “XMLPort: Import Into Temporary Table

  1. Brian Blackstone

    2015-09-08 at 06:26

    YES! This is exactly what I’ve been looking for! I missed it because of the simplicity! I couldn’t figure out how to get the temporary table data back from the XMLPort import, without writing it to a real table first. Creating a GetTemporaryData function fixes that. Thank you so much!

    Like

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
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

Mark Brummel Blog | Microsoft Dynamics NAV

Master Classes Design Patterns and more...

Vjeko.com

ideas in the cloud

Goprowe AB

Reflections from the ERP field

ArcherPoint Developer Blog

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

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

Navision-Girl.Com

Reflections from the ERP field

Kine's Info

Reflections from the ERP field

blog.wibeck.org/

Just another WordPress.com site

NAV/SQL Performance - My Two Cents

Reflections from the ERP field

%d bloggers like this: