Dynamics User Group
Since 1995 - The Microsoft Dynamics Online User Community

Status of Dataport Import

rated by 0 users
This post has 5 Replies | 2 Followers

Not Ranked
Posts 4
Points 60
michaele Posted: 08-28-2008 14:42

I use a Dataport to Import from a txtfile to a table.

In "Dataport - OnPostDataport()" I remove the file I have Imported, like this :

IF EXISTS(CurrFile.NAME) THEN BEGIN
  FileName := CurrFile.NAME;
  CurrFile.CLOSE;
  ERASE(FileName);
END;

FileName is a Global Variable of Text - 255

I only wish to remove the file if the Import have been successfull, that is all data is imported to the table.
Is there a property on the Dataport to see if the Import was successfull ?

  • | Post Points: 20
Top 150 Contributor
Male
Posts 129
Points 2,695

Ussually you should get error message if import is not successful. After error you will not get to OnPostDataport, so file will not be deleted.

Viktoras Danielius Microsoft Dynamics NAV Developer
  • | Post Points: 35
Top 50 Contributor
Male
Posts 430
Points 4,135

Before calling ERASE I would do like this (in OnPostDataport):

IF NOT RENAME(CurrentFilePathName, NewFilePathName) THEN 
  ERROR('SomeErrorMessage');

COMMIT;  //if this one fails, the file only have been moved, not erased
ERASE(NewLocation);  //syntax may be "IF NOT ERASE(..."

  • | Post Points: 20
Not Ranked
Posts 4
Points 60

Thankyou for your time to answer my question.

 Unfortunately the code in OnPostDataport is performed even if I recieve an error message.
So the file gets deleted even if an error occur.

  • | Post Points: 5
Not Ranked
Posts 4
Points 60

anfinnur:

Before calling ERASE I would do like this (in OnPostDataport):

IF NOT RENAME(CurrentFilePathName, NewFilePathName) THEN 
  ERROR('SomeErrorMessage');

COMMIT;  //if this one fails, the file only have been moved, not erased
ERASE(NewLocation);  //syntax may be "IF NOT ERASE(..."

Thankyou for spending time answering my question. 

Yes, this code is much better.
I agree it would be wiser to rename the file and not delete it, so recovery of the file is possible.

Still I would like to be able to abort the file rename operation if the transaction have failed.
Is there a way to detect weather the transaction was successfull ?

  • | Post Points: 5
Not Ranked
Posts 4
Points 60

I found a solution :-)
If I perform a COMMIT before doing the ERASE, then the Error appear before I do the file operation.

The Code in Dataport - OnPostDataport() Trigger will the look like this:

IF EXISTS(CurrFile.NAME) THEN BEGIN
  FileName := CurrFile.NAME;
  CurrFile.CLOSE;
  COMMIT();  //Any Error appear here, before File operation is performed
  IF NOT ERASE(FileName + '.bak') THEN BEGIN
    //Unable to delete .bak file is not critical
  END;
  IF NOT RENAME(FileName, FileName + '.bak') THEN
    ERROR(Unable to rename : ' + FileName);
END;

  • | Post Points: 30
Page 1 of 1 (6 items) | RSS


Copyright Dynamics User Group, 1995-2008, all rights reserved. The Dynamics User Group is not affiliated with Microsoft Corporation.