Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

XML Port Imports the same entry multiple times

Posted on by 3,957

Hi All,
I've a requirement where I need to import the csv file into NAV using XMLPort.
But the issue is XMLPort repeats the entry n number of times.
For eg:
Data in CSV File is

Entry | DataValue1 | DataValue2
------+-------------+-------------

1          Hello            06/07/2018

2          hi                 06/07/2018

Data Imported is

Entry | DataValue1 | DataValue2
------+-------------+-------------

1          Hello            06/07/2018

2          Hello            06/07/2018

Also, I'm try to the same by calling the XMLport through code. But how do I set the path for the CSV file to be imported. Kindly suggest.

*This post is locked for comments

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: XML Port Imports the same entry multiple times

    Thanks for the sample code.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: XML Port Imports the same entry multiple times

    To set the file name, you can use MyXMLPort.FILENAME([NewFileName]).

    Check also this sample that could be useful (direct reading of a file as input):

    //VARIABLES:

    Name DataType Subtype Length

    SalesOrderXmlFile Text

    XmlStream InStream

    IsImported Boolean

    ImportXmlFile File

    FileMgmt Codeunit File Management

    //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');

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans