Scheduler Script
A script file can be created and modified by selecting Tools, Script Editor. All the configured scripts (file extension .scs) are listed. For an example of the script syntax, see the XLRprocess script in the project. Note that a line starting with a semi-colon (;) is treated as a comment.
Schedule Scripts are for backwards compatibility. For new applications, an Update Action List configuration is the recommended approach.
Scripts are run using the Run a Schedule Script Action.
A script can contain two sections, Command and Trigger. Each section is written in the script by enclosing it in [].
Command Section
The Commands section is defined by [Commands] in the script file followed by a list of commands. Any command listed under this section is executed when the script file is ran. This is useful when is there are a number of actions that need to be processed collectively on a common schedule condition regardless of any configured Trigger sections in the script.
Example: A script to update and print a worksheet.
[Commands]
command1 = UpdateSheet 'DailyReport.Template' command2 = PrintSheet 'DailyReport.Template'
In addition, to actions, the Command section supports simple script keyword as follows:
Wait n
Pause the script for n seconds
Init v n
Initialize the variable v to n. Variables supported are x, y, and z.
Incr v n
Increment the variable v by n.
Start Loop n
Indicates the start of a loop to be executed n times.
End Loop
Indicate the end of the loop.
Goto x
Jump to the script commandx
Example: Update the groups 1 to 5 in a worksheet and the print the command. Note that without the script this can be accomplished by six schedule commands.
[Commands]
; Initialize x to 1
command1=Init x 1
; Set up a loop to iterate 5 times
command2=Start Loop 5
; Update the Daily Report for the specific group (1-5)
command3=UpdateGroupSheet 'DailyReport.Template' '{x}'
command4=Wait 2
command5=Incr x 1
; End the loop
command6=End Loop
; Print the worksheet
command7=PrintSheet 'DailyReport.Template' 'default'Trigger Section
The Trigger section is defined by [TriggerX] in the script file where X is a numeric value starting at 1 allowing multiple Trigger sections in a single script file. The script is used to monitor the content of a folder for a new file and perform commands when that happens.
Example: Monitor a folder for a CSV file and run report when that happens.
In addition to actions, the Trigger section supports simple script keyword as follows:
Type, either 1 or 2.
Type 1 is a file trigger where the FileSource directory is monitored and when one or more files are found in the folder the most recent file (based on modified date or created date depending on the FileLock setting) is processed based on the other settings in the section.
Type 2 is a file trigger where the File Source directory is monitored and when one or more files are found in the folder every file found is processed based on the other settings in the section.
FileSource
The folder to monitor for new files. This setting must be specified.
FileFilter
The filter to apply when monitoring for new files in FileSource. For example, to monitor for CSV files, set to *.csv. To monitor for every Excel workbook file that starts with Flow, set to Flow*.xls*. If this is not specified, the default is *.* which processes any file in the directory.
FileLock, either 0 or 1
This setting determines how files are considered for the trigger. If this is set to 0, every file that exists in the FileSource directory and satisfies the FileFilter is considered. If this is set to 1, each file must also be accessible (e.g., the file is not locked) in order to be considered.
If Type is set to 1 and this setting is 0, the most recent file in the folder is determined using the file creation date. If this setting is 1, the most recent file is determined using the file modified date.
If this setting is not specified, the default behavior is 1.
FileMaster
When the file is found in the folder, it can be copied to the FileMaster setting so that subsequent commands can deal with a consistent file name. If specified, it must be specified with a full path. If this functionality is not required, this keyword may be omitted.
FileArchive
Once a file is processed it can be moved to another folder so it is not processed again. This setting is the folder the processed files are moved to. This is an optional setting.
If the file to process already exists in the folder specified for this setting, when archived, a number is appended to the file name (starting at 1) so it can be archived. For example, if the file is ABC.txt and ABC.txt has already been archived, it is archived as ABC_1.txt. If another ABC.txt is processed, it is archived as ABC_2.txt and so on.
If this setting is not specified, after the file is processed, a file named _lastprocessed plus the script file name and the section is created in the Data folder of the project under the XLRprocess folder. For example, if the script file is named CSVMonitor and the section is Trigger1, the file name is:
_lastprocessed_CSVMonitor_Trigger1.ini
This file contains 2 timestamps, one for the last modified time and one for the last created file time. If FileLock is 0, the last created file time is stored, whereas if the FileLock is set to 1 the last modified file time is stored.
If you wish to have all the files in the FileSource directory considered, delete this file.
FileTarget
The register variable (e.g., RG000) to set with short name of the file found in FileSource. The name does not include the file path or extension. If this functionality is not required, this keyword may be omitted.
FileFullTarget
The register variable (e.g., RG001) to set with the full name of the file found FileSource. The name includes the file path and extension. If this functionality is not required, this keyword may be omitted.
Example: Monitor the folder c:\Data for a CSV file. When found, set RG000 with the short name, RG001 with the long name, copy it to c:\mydata\mymaster.csv and then move it to c:\Data\archive. Run command actions to update report and save it to PDF (using the register RG000, RG001 and the file mymaster.csv).
[Trigger1] Type=1 FileSource=C:\data FileFilter=*.csv FileLock=1 FileTarget=RG000 FileFullTarget=RG001 FileMaster=C:\mydata\mymaster.csv FileArchive=C:\data\archive Command1=UpdateSheet'MyTemplate.Template' Command2=SaveSheetPDF'MyTemplate.Template' ''
Note that if all the files in c:\Data need to be processed, set the Type to 2.