XMLport - Import from CSV and COUNT

PurpleHazePurpleHaze Member Posts: 42
Hi,



I am importing some records from .csv file with XMLport.

Now, I want to put progress bar so I would need to count records that I need to import.


Is there any way to count records even before processing all of them? And which trigger I should use?



Thank you very much for your answers!


Greetings

Answers

  • PurpleHazePurpleHaze Member Posts: 42
    No idea about progress bar for XMLport at all?
  • David_CoxDavid_Cox Member Posts: 509
    On before loading the file in the xml port count the nodes in the xml file or lines in the csv file.
    Trigger OnPreXmlPort();
    Filename = CurrXMLPort.FILENAME;

    XMLDoc = type:DOMDocument
    XNLNodeList = type: IXMLDOMNodeList

    If we were importing Items from an XML File and our nested Node was 'Item' we can get the count something like this untested code.
    CREATE(XMLDoc);
    XMLDoc.load(CurrXMLPort.FILENAME);
    XMLNodeList := XMLDoc.selectNodes('//Item');
    TotalRecNo := XMLNodeList.length; 
    

    EDIT:
    Not a xml file so the above would not work, for CSV we need to do it different as length is not the number of lines!


    There is no CurrFile like a dataport so you could do something like above and count the lines in the csv file, open the file loop and count the lines and close the file!
    Variables:
    MyFile = FILE
    TempTextVariable = Text 1000
    TotalRecNo = Integer
    CLEAR(MyFile);
    MyFile.TEXTMODE := TRUE;
    MyFile.OPEN(CurrXMLPort.FILENAME);
    WHILE MyFile.POS <> MyFile.LEN DO BEGIN
      MyFile.READ(TempTextVariable);
      TotalRecNo := TotalRecNo + 1;
    END;
    MyFile.CLOSE;
    

    Now you can add a progress bar as normal!


    HTH

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • PurpleHazePurpleHaze Member Posts: 42
    Hi David,


    This is awesome!!! =D> =D>

    Thank you so much!!!!! :thumbsup: :thumbsup: :thumbsup:


    I own you a beer!!! \:D/ \:D/


    Cheers!
  • DamjanDamjan Member Posts: 94
    David_Cox wrote: »
    On before loading the file in the xml port count the nodes in the xml file or lines in the csv file.
    Trigger OnPreXmlPort();
    Filename = CurrXMLPort.FILENAME;

    XMLDoc = type:DOMDocument
    XNLNodeList = type: IXMLDOMNodeList

    If we were importing Items from an XML File and our nested Node was 'Item' we can get the count something like this untested code.
    CREATE(XMLDoc);
    XMLDoc.load(CurrXMLPort.FILENAME);
    XMLNodeList := XMLDoc.selectNodes('//Item');
    TotalRecNo := XMLNodeList.length; 
    

    EDIT:
    Not a xml file so the above would not work, for CSV we need to do it different as length is not the number of lines!


    There is no CurrFile like a dataport so you could do something like above and count the lines in the csv file, open the file loop and count the lines and close the file!
    Variables:
    MyFile = FILE
    TempTextVariable = Text 1000
    TotalRecNo = Integer
    CLEAR(MyFile);
    MyFile.TEXTMODE := TRUE;
    MyFile.OPEN(CurrXMLPort.FILENAME);
    WHILE MyFile.POS <> MyFile.LEN DO BEGIN
      MyFile.READ(TempTextVariable);
      TotalRecNo := TotalRecNo + 1;
    END;
    MyFile.CLOSE;
    

    Now you can add a progress bar as normal!


    HTH

    David

    Hi All,
    Hope I can borrow this thread:)
    I have written an XMLPort where I import data from text file (*.TXT), everything works fine if I open NAV client where NAV server and NAV client is installed (NST is running), but if I open the NAV client on a Terminal Server (where NST is not running), then I get an error:

    Could not find a part of the path 'E:\TESTDATA\REWE-CSV0413.txt.txt'.
    4n0fsztuyz5t.png


    XMPort code is this:
    ap4axqobhjcc.png

    error pops here:
    ImportedCSVFile.OPEN(currXMLport.FILENAME);
    vz93qoq6lmfh.png

    Thank you
    BR Damjan
  • ftorneroftornero Member Posts: 522
    Hello @Damjan,

    In this case you need first to download the file from the server and then process it.

    You can use the codeunit 419 (File Management) to do that.
    
    clientFile := fileMgt.ClientTempFileName('');
    fileMgt.DownloadToFile(currXMLPort.FILENAME, clientFile);
    ImportedCSVFile.OPEN(clientFile);
    ....
    Regards.
  • DamjanDamjan Member Posts: 94
    Hi,

    I tried with @ftorenore suggestions, but it works on the NAV Server, but it does not work on terminal server where only NAV client is installed. I am working this on NAV2013 R2 version:)

    Error pops:
    d3oasfis4o9w.png

    Debugger stops here
    pt984zbszq5c.png

  • DamjanDamjan Member Posts: 94
    I found out that it works as expected if I save file that has to be imported to the server where NAV Application Server is running
    \\192.168.1.239\e$\TESTDATA
    As file browser dialog opens, I have to select that exact location: \\192.168.1.239\e$\TESTDATA\file.txt

    but, if I save the file to my desktop or on my local disk, and as file browser dialog opens and I select local location: C:\testdata\file.txt than error pops: File was not found.

    I checked the user permissions and user has full permissions on folder where file is saved, and user is opening NAV client that runs under his user account, but NST user is not the same user as user who has opened the NAV client.
  • ftorneroftornero Member Posts: 522
    Hello @Damjan,

    You can try the other way around and see what happens.
    serverFile :=  fileMgt.UploadFileSilent(currXMLPort.FILENAME);
    ImportedCSVFile.OPEN(serverFile);
    .....
    

    Regards
  • DamjanDamjan Member Posts: 94
    Thanks that works as expected.
Sign In or Register to comment.