Sequential Import of Multiple files into Navision Using Dataport

Can you import multiple files sequentially using Navision dataport?

Say you will put all the files to import into Navision in a folder and one navision dataport will import all the files one by one into Navision.

Here is how I have done it –

Created a new form and put a text box where user can mention the folder path from where the files will be imported. Also put a command button which will start the import process clicked.

Took the following variables in C/AL Globals –

WIN Dialog Type -> to display the progress of import
FileRec Record type -> referenced to virtual table ‘File’
CTR Integer type -> to count the number of files imported
TransImport Dataport type -> referenced to a dataport which will be run repeatedly depending on number of files present in the folder
FilePath Code type -> to store the file path of the folder

Also took a text constant for displaying the import progress in the dialog box ‘WIN’

Text50000 Importing File #1#####################Count of File #2#####

Once the definition of variables are done, write the following code in the OnPush trigger of the command button –

ImportButton – OnPush()

WIN.OPEN(Text50000); // opening the dialog box to display the import status FileRec.SETRANGE(Path,FilePath); // Accessing the folder path mentioned by the user and stored in the ‘FilePath’ variable.
FileRec.SETRANGE(“Is a file”, TRUE); // Excluding the sub folders (if any) present in that folder.
IF FileRec.FINDFIRST THEN BEGIN // Ensuring that at least 1 file is present in the folder and pointing the instruction pointer to the first files in the folder.
REPEAT // Starting the loop to read files one by one
CTR += 1; // Capturing the file count
WIN.UPDATE(1,FileRec.Name); // Displaying file name in the dialog box.
WIN.UPDATE(2,CTR); // Displaying file counter in the dialog box.
CLEAR(TransImport); //Clearing the previous instance of the dataport
TransImport.FILENAME := FileRec.Path + ” + FileRec.Name; // Sending the file name with the file path to the dataport.
TransImport.RUNMODAL // Running the dataport.
UNTIL FileRec.NEXT = 0; // Loop condition till all the files in the folder is read.
END;
MESSAGE(‘Import Done’); // Informing user that import is complete
WIN.CLOSE; // Closing the dialog box
Note: Your variable name can be different and you need to adjust your code as per your variable definition.

Now run the form and enter the folder path where your files to be imported are stored and click on the button ‘Import’. This will start the import process and will continue till all the files from the folder is imported into the database.

You can automate the same with the help of timer trigger of the form or using an application server. Will discuss the process of automating it in our future discussion.

All the best. Try it.

3 Replies to “Sequential Import of Multiple files into Navision Using Dataport”

  1. You have to set “UseReqForm” to “No” in the properties of the dataport in order to run the dataport for all the files in the folder.

    cheers
    Ted

  2. This seems to just open the dataport in the background waiting for you to click on the OK button for it to run?

    I thought it would automatically run the dataport?

    Have I missed something..

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.