Run XMLPort with no user interaction.

GreatScott000GreatScott000 Member Posts: 40
edited 2014-03-05 in NAV Three Tier
In NAV 2013 (70.35345)
I need to import data into several companies in a database. I don't want the user to do anything but launch the process. Any suggestions?

This is what I used to do...
In NAV2009 Classic I would just create a report that cycles through the companies, passes the company name to a Dataport variable through a function (ImportData.SetCompany), sets the FILENAME of the import (ImportData.FILENAME := <path><company name>.txt), run the Dataport (Import.RUNMODAL). The Dataport does a CHANGECOMPANY and imports the data; done. Piece of cake.

This won't work in 2013 because...
The same scheme does not work in 2013 with XMLports.
Using XMLport "variables" always prompts for a filename even if you specify it in code (ImportData.FILENAME) and the XMLport Direction is IMPORT. This becomes tedious and error prone each time the client has to navigate to the file location and pick the right file.

To work around this it looks like you can use XMLPORT.IMPORT(XMLportID, <FileStream>) but then I don't have anyway to change the company into which the data gets imported. So again this becomes tedious because the user would have to run the XMLport, change companies, navigate to the "link" for the import again and run the XMLport, repeat for every company.

This particular client only has 10 or 12 companies so it is workable but there are clients with 20+, 50+, 70+ companies and this becomes a real issue.

<rant>
I suppose I could write something that would work through WebServices (get the list of companies, call a Codeunit in that company that does the XMLport.IMPORT, etc.) but the clients don't use Web Services and I don't really think I should have to get that inventive to resolve a problem that could be resolve within the client before we got "new" and "improved" technology.

Why have we lost functionality with XMLports in 2013 vs. Dataports in 5.0 or even 2009? If XMLport variables would just not prompt for the filename if one is specified it would be done.

It seems we take a few steps forward and we find a U-turn in the technology that seems obviously lacking (to me at least). ](*,)
</rant>

Comments

  • ara3nara3n Member Posts: 9,256
    You need to use startsession() and can start a codeunit in a different company.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • GreatScott000GreatScott000 Member Posts: 40
    So the answer is this. My biggest mistake was calling RUN instead of IMPORT. Only draw back is the Security warning because File Management uses .NET variables. But only have to answer the prompt once for the operation and not for each company.
    //in Company OnAfterGetRecord()
    //FileMgmt is Codeunit 419 File Management
    ServerFilename := FileMgmt.UploadFileSilent(STRSUBSTNO('<path>\%1.txt', Name)); //Assume data is in file with Company.Name as filename, Move file to NST
    ImportFile.OPEN(ServerFilename);
    ImportFile.CREATEINSTREAM(inFile);
    
    //ImportData is an XMLport variable
    CLEAR(ImportData); //Reuse XMLport variable
    ImportData.SetCompany(Name);
    ImportData.SETSOURCE(inFile);
    ImportData.IMPORT;  //Use IMPORT function [b]not[/b] RUN.  Run always prompts for filename.
    
    ImportFile.CLOSE;
    ERASE(ServerFileName);  //Remove file from Server
    
Sign In or Register to comment.