in

Dynamics User Group

Since 1995 - The Microsoft Dynamics Online User Community

Status of Dataport Import

Last post 08-29-2008 10:03 by michaele. 5 replies.
Page 1 of 1 (6 items)
Write a New Post Sort Posts: Previous Next
  • 08-28-2008 14:42

    • michaele
    • Not Ranked
    • Joined on 08-28-2008
    • Posts 4
    • Points 35

    Status of Dataport Import

    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
  • 08-28-2008 16:09 In reply to

    • Viktoras
    • Top 150 Contributor
      Male
    • Joined on 11-27-2002
    • Lithuania
    • Posts 129
    • Points 2,172

    Re: Status of Dataport Import

    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
  • 08-28-2008 17:10 In reply to

    • anfinnur
    • Top 50 Contributor
      Male
    • Joined on 10-26-2000
    • Faroe Islands
    • Posts 426
    • Points 3,920

    Re: Status of Dataport Import

    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
  • 08-29-2008 7:25 In reply to

    • michaele
    • Not Ranked
    • Joined on 08-28-2008
    • Posts 4
    • Points 35

    Re: Status of Dataport Import

    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
  • 08-29-2008 7:31 In reply to

    • michaele
    • Not Ranked
    • Joined on 08-28-2008
    • Posts 4
    • Points 35

    Re: Status of Dataport Import

    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
  • 08-29-2008 10:03 In reply to

    • michaele
    • Not Ranked
    • Joined on 08-28-2008
    • Posts 4
    • Points 35

    Re: Status of Dataport Import

    Answer

    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: 5
Page 1 of 1 (6 items)


Copyright Dynamics User Group, 1995-2008, all rights reserved. This website and user group are independent and not affiliated with the Microsoft Corporation.