web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

NAV 2013 R2 - XML Port, How to close the file that the XML Port uses for importing

(0) ShareShare
ReportReport
Posted on by

Dear Developers,

I'm writing in order to ask for some help with File management in 2013 r2 xml port.

The "problem" is, that after importing the records from the file, I'd have to move it from the folder path it was opened from, to another folder (based on whether the import was successfull (in this case it has to be moved to an "Archived" folder), or it finished with errors (in which case it has to be moved to a "Failed" folder). The thing is, that in 2009 i could simply use the "currFile.CLOSE" command to close the file and then move it, but with 2013, this commandline was (re)moved somehow, and I just can't seem to work my way around it.

However, I found a codeunit called File Management (419), in which there IS a function for closing a file, but as a reference it expects a 'File' type variable, which i can not seem to pass from the XMLPort via. currXMLPort.FILENAME (Type Conversion error occurs).

I'm pretty desperate now, so if any of you might have any ideas or hints as to how this problem could be solved, please feel free to share your mind with me (or us, if there are any other developers who are concerned as well regarding this matter :) )

Regards : Ruben 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    keoma Profile Picture
    32,729 on at

    try following sample code:

    // the variables

    Name DataType Subtype Length

    SalesOrderXmlFile Text

    XmlStream InStream

    IsImported Boolean

    ImportXmlFile File

    FileMgmt Codeunit File Management

    // the code

    SalesOrderXmlFile := 'C:\Temp\SalesOrder.xml';

    ImportXmlFile.OPEN(SalesOrderXmlFile);

    ImportXmlFile.CREATEINSTREAM(XmlStream);

    IsImported := XMLPORT.IMPORT(XMLPORT::"Sales Header", XmlStream);

    IF (IsImported = TRUE) THEN

     MESSAGE('The import from XML is complete.')

    ELSE

     MESSAGE(GETLASTERRORTEXT);

    ImportXmlFile.CLOSE;

    FileMgmt.MoveClientFile(SalesOrderXmlFile,'c:\temp\archive\salesorder.xml');

  • Verified answer
    Community Member Profile Picture
    on at

    Hello Jonathan, Thank you for your quick response.

    We managed to solve it by making a temporary copy of the file, process it and depending on the outcome, we moved the original file to the desired location.

    Again, thank you for replying! Regards:

    Ruben H.

  • keoma Profile Picture
    32,729 on at

    my pleasure. if my answer also satisfied your question, please verify.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans