Skip to main content

Advanced Scripting

The following example introduces user provided arguments. This makes the script more powerful as the behavior can be changed without having to create or update the script.

As mentioned before, user provided arguments precede the JobFlow provided arguments so the order in which arguments are read by the script needs to reflect this.

In this script example a user provided value is checked and used to set the 3rd party app behavior.

advanced.bat
:: Disclaimer: scripts are provided as-is and most of them use tools that are open source
:: or require a (small) license fee when used in a commercial environment. It is the
:: responsibility of the end user that use scripts to respect the license agreement for
:: these tools. EFI can not be held responsible in any way if scripts don't behave like
:: they should do resulting in any form of financial loss or downtime. Have a good day.

:: [Description, link to 3rd party app]
:: [Author], [Date]

:: User provided arguments
set txtValue=%~1
:: Manage user provided arguments. By using this trick we can manage arguments a lot easier
shift /1

:: JobFlow arguments, information that JobFlow makes available to the script
set INPUT=%~1
set OUTPUT=%~2
set JOBNAME=%~3
set WORKFLOW=%~4
set PREFLIGHT=%~5
set VAULT=%~6
set NEXTMODULEID=%~7

:: Static variables, information that we use to make the script easier to manage
:: Location of this script
set pathScript=%~dp0
:: Name of this script
set ScriptName=%~n0
:: File path where we want to save the log file. We like to use JobFlow Vault.
set pathLog=%VAULT%\%ScriptName%.log
:: File path where we will look for any additional applications we want to use
set pathInclude=%pathScript%\_include

:: Check user provided arguments
if /I "%txtValue%" EQU "" (
>>%pathLog% echo %DATE% %TIME% [ERROR] User value cannot be blank. Exit script.
exit /b 1
)

:: Helper Apps
:: #scriptname#
:: Where in the _include path can we find the application we need?
set pathApp=%pathInclude%\app.exe
:: Make sure the application exists
if not exist %pathApp% (
>>%pathLog% echo %DATE% %TIME% [ERROR] Cannot find application at %pathApp%. This is serious. Exit script.
exit /b 1
)

:: This is where we process the JobFlow job with the 3rd party app.
:: Note: this command is an _example_ and is different for every app.

:: It is advisable to wrap all path variables with quotations to ensure path with spaces work
:do_something
"%pathApp%" "%INPUT%" %txtValue% "%OUTPUT%\%JOBNAME%.pdf"
:: Check if something worked
if %ERRORLEVEL% NEQ 0 (
>>%pathLog% echo %DATE% %TIME% [ERROR] An error occurred while doing something. Exit script.
exit /b 1
)
>>%pathLog% echo %DATE% %TIME% [INFO] We processed %INPUT% with %pathApp% to %OUTPUT%\%JOBNAME%.pdf

:: We're done. Back to JobFlow.
:success
exit /b 0

In JobFlow, the script would be called as follows in the Connect module script settings: c:\scripts\advanced.bat "user value" The 3rd party application has to exist at c:\scripts\_include\app.exe