1. Moving import file into archive

    Article: AN0002445Updated: 13.11.2020

    We may want to transfer the import file from the path defined in the import into an archive folder as a step within the import. We can successfully use scripts that we can run at various import phases, before the import or after the import for this purpose. Below we are distinguishing two scenarios:

    1. Transfer of the import file only in case of a successful import run

    If we want to move the file just in case of a successful import run, we will use below script in the event Start after import end.

    //move the file into archive
    if (OGActualImportRun.ResultStatus == 3) //Running
    {
    var destFileName = OG.TextUtils.Format( "C:\\import\\Archive\\{0:yyyy-MM-dd}_file_name_{1}.txt", OG.DateTime.Now, OG.Guid.CreateNew());
    OG.IO.FileMove(OGActualImport.SourcePath, destFileName);
    }

    We can notice two things in the above script:

    • duplication of back slashes in the archive folder (Back slash is an escape character. Without duplication this character would not be present in the resulting string.)
    • name of the file that we have compiled from the current date, actual file name and GUID sequence. This will ensure that in case the same file is imported several times during one day it will be always saved in the archive folder under a different name.

    2. Transfer of the import file also in case of failed import

    Sometimes we may want to move the file also when the import fails. The reason for this can be that we want to prevent new attempts to import an erroneous file. We may notify about failed import by means of standard notification settings in the import.

    We will use two scripts in the case:

    Script into the import event Start before import start.

    //copy the file into archive under another name
    if (OGActualImportRun.ResultStatus == 3) //Running
    {
    var destFileName = OG.TextUtils.Format( "C:\\import\\Archive\\{0:yyyy-MM-dd}_file_name_{1}.txt", OG.DateTime.Now, OG.Guid.CreateNew());
    OG.IO.FileCopy(OGActualImport.SourcePath, destFileName, true);
    }

    Above script will first copy the file into the archive, resp. it saves it under a unique name. After that an import runs and finishes OK or with failure. Deletion of the file will then be secured by an activity following the import. This may be next step of the job or workflow of type Script:

    //delete the file

    OG.IO.DeleteFile("C:\\import\\Archive\\file_name.csv");

     

×