Importing daily file with a variable name

Running SAGE 100 v2018 and trying to import a file on a daily basis that will contain a data stamp on it. What I'm trying to do is automate the process by creating a scheduled task in Windows that opens a batch file that runs the VI program. The only issue is that the file being imported has a date stamp as part of the name so each time the batch is run, an error occurs because the file cannot be found. One option is to rename the file once it is placed in the static directory but I was hoping there might be a way to import the file without modifying the name. Any suggestions would be much welcomed.

  • Script to copy the correct date-stamped file into the file name / path used in VI settings, then trigger the job, with Perform logic to rename the file after import.  You end up with two copies of the file, but I consider that a good thing.

  • in reply to Kevin M

    First, I appreciate the turbo speed response, Kevin...thank you.  Unfortunately my strengths are not within VI so most of what you said went over my head.  I'm not sure what you mean by "script to copy.."  On the flipside, I do know how to write a Perform logic to rename the file and place it in an "archive" folder.

  • in reply to Paul Smith - Bretthauer

    External VBScript or batch file commands. Google can tell you how.  There are lots of resources with examples of moving / copying text files.  For VI you just need the data in a specific file since you can't change that dynamically.

    For triggering a VI job from a batch file, the Sage KB has instructions for that.

  • You can use VI's Perform Logic On Execution event to modify the IMPORTFILENAME$ variable.

    If the directory and file name excluding the date is static, you can hardcode that part in your perform logic or you can manipulate the current value.  

    You can use ProvideX's DTE function to format the current date using any mask to match the date format you expect to be in the file name.  You can also use the coSession/%SYS_SS object's date methods to format a date.

    However, IIRC, by the time the On Execution event occurs, the file has been opened and you need to close it, it should use the IMP_CH variable.  After you get the file name with the current date in it, you need to reopen the file.  You should be able to easily test this.

    Alternatively, you can use Kevin's approach which works equally well.  You can either use a batch file or a VBScript file to handle renaming the file, launching the VI job, and then if needed, copying/moving/renaming files once the import completes.  Just keep in mind that if you have file processing logic after launching the VI job, you need to wait until the job completes but because of the way the external sage 100 commands work, they return to the script as soon and the task is launched, NOT after the task completes.  For this reason, you may find it easier to use perform logic in the completion event instead.

  • in reply to David Speck

    Absolutely, use Perform Logic to rename after the import. 

    My suggested scripts / batch commands were for before the job is triggered, which I find to be the most flexible since you don't need to predict the input file name.  I've used that technique to download all new csv files from an FTP/SFTP site, consolidate them into an import file, trigger VI, then after VI is done rename the VI source file and email the results (Visual Cut, with the SY_ActivityLog rows for the job).  No real programming involved... just VBScript and batch files.

  • in reply to David Speck

    Thank you David.  I appreciate the options.  I have some things to consider but I may just go with the batch file method that will rename the file then, once completed, move the file to a different location.

  • in reply to Kevin M

    Thank you Kevin for the details.  Like I told David, I appreciate the options and will most likely go with the renaming within the batch, execute the VI job, then rename and move to a different folder.