XMLPort authomatocally launch at NAV 2013

Hello, all!

I have a task I can’t solve. I make an XMLPort which imports sales Orders from XML files. There is a directory at NAS with XML files (first dir) and a directory at NAS with archive XML files (second dir). I made a button. When user press this button, NAV finds all XML files in 1st dir, runs XMLPort for all files in series (This step creates sales Orders and lines) and move files to 2nd dir. All works correctly, but I need to NAV automatically run this XMLPort without users action. Any idea?

Code of OnAction trigger of page action:

////// Action //////

SalesSet.GET;

DirectoryInfo := DirectoryInfo.DirectoryInfo(SalesSet.“Orders from Customers”);

List := DirectoryInfo.GetFiles(’*.XML’);

enumerator := List.GetEnumerator;

WHILE enumerator.MoveNext DO

BEGIN

FileInfo := enumerator.Current;

xmlPortUploadOrder.FILENAME(SalesSet.“Orders from Customers” + FileInfo.Name);

xmlPortUploadOrder.RUN;

CLEAR(xmlPortUploadOrder);

FileInfo.CopyTo(SalesSet.“Archive Orders from Customers” + FileInfo.Name, TRUE);

FileInfo.Delete;

END;

////// Action //////

Where

Name DataType Subtype Length

DirectoryInfo DotNet System.IO.DirectoryInfo.‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

FileInfo DotNet System.IO.FileInfo.‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

List DotNet System.Collections.Generic.List`1.‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

enumerator DotNet System.Collections.IEnumerator.‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

SalesSet Record Sales & Receivables Setup

xmlPortUploadOrder XMLport Orders From Web

I find a solution. I setup auto launch of codeunit in Job Queue, function XMLPORT.IMPORT helps to ignore the window with file selection.

That’s my code of codeunit:

SalesSet.GET;

DirectoryInfo := DirectoryInfo.DirectoryInfo(SalesSet.“Orders from Customers”);

List := DirectoryInfo.GetFiles(’*.XML’);

enumerator := List.GetEnumerator;

WHILE enumerator.MoveNext DO

BEGIN

FileInfo := enumerator.Current;

XmlFile.OPEN(SalesSet.“Orders from Customers” + FileInfo.Name);

XmlFile.CREATEINSTREAM(InputStream);

IF XMLPORT.IMPORT(XMLPORT::“Orders From Web”, InputStream) THEN

BEGIN

FileInfo.CopyTo(SalesSet.“Archive Orders from Customers” + FileInfo.Name, TRUE);

FileInfo.Delete;

END;

XmlFile.CLOSE;

END;

Sorry for mistake in code. I can’t delete file before I close one.

Real code:

SalesSet.GET;

DirectoryInfo := DirectoryInfo.DirectoryInfo(SalesSet.“Orders from Customers”);

List := DirectoryInfo.GetFiles(’*.XML’);

enumerator := List.GetEnumerator;

WHILE enumerator.MoveNext DO

BEGIN

FileInfo := enumerator.Current;

XmlFile.OPEN(SalesSet.“Orders from Customers” + FileInfo.Name);

XmlFile.CREATEINSTREAM(InputStream);

IF XMLPORT.IMPORT(XMLPORT::“Orders From Web”, InputStream) THEN

BEGIN

FileInfo.CopyTo(SalesSet.“Archive Orders from Customers” + FileInfo.Name, TRUE);

XmlFile.CLOSE;

FileInfo.Delete;

END

ELSE

XmlFile.CLOSE;

END;