Codeunit calls Dataport.RUN

Hi all,

Once again I turn to your experience and knowledge.

I have a codeunit that checks if there is any *.csv files in a folder and if so fills the DATAPORT.FILENAME and calls DATAPORT.RUN. Here is the code:

ServerFolder := ‘C:\Folder’;

FileSystem.SETRANGE(FileSystem.Path, ServerFolder);
FileSystem.SETRANGE(FileSystem.“Is a file”, TRUE);
FileSystem.SETFILTER(FileSystem.Name, ‘@*.csv’);

IF FileSystem.FIND(’-’) THEN BEGIN
REPEAT
old_name := ‘’;
new_name := ‘’;

file_name := ‘Backup’ + ‘_’ + FileSystem.Name;

old_name := FileSystem.Path + ‘’ + FileSystem.Name;
new_name := FileSystem.Path + ‘’ + file_name;

file_to_import := FileSystem.Path + ‘’ + FileSystem.Name;
IF EXISTS(file_to_import) THEN BEGIN

IF FileSystem.Size <> 0 THEN BEGIN
DataportObject.FILENAME(file_to_import);
DataportObject.RUN;
END;

FILE.RENAME(old_name, new_name);

IF FILE.COPY(new_name, FileSystem.Path + ‘\Backup’ + file_name) THEN
FILE.ERASE(new_name);
END;
UNTIL FileSystem.NEXT = 0;
END;

The dataport properties are:


Import: Yes
FileName: <>
FileFormat:

UseReqForm: No
TransactionType: Update
Permissions:

I have to run the codeunit twice. The first time it runs I get the following error:

“You cannot change thtransaction type after you start a transaction.
A transaction starts when the program executes the first database operation, for example: FIND, NEXT, INSERT, DELETE, MODIFY, SUM and COUNT.
The error occurred because you where trying to change the transaction type from UpdateNoLocks to Update.”

The second time everything runs perfectly (both codeunit and dataport).

My problem is that this codeunit is to be run in a Navision scheduled task and when the error occurs the task doesn’t run.

Thank you for your time and help,

ZP.

Hi

Go to the dataport properties and change the TransactionType property to UpdateNoLocks and try reffer the belo picture

3806.untitled1.bmp (422 KB)

Thanks

Jerome Marshal.J

Thank you!

It solved the problem. Can you tell me something more about the difference about Update and UpdateNoLocks?

Once again thank you!

ZP.