Creating a Script File for the Command Line BIC
Before you can use the Command Line BIC in a process flow, you must create a script file for the BIC to execute. Using a text editor, open a new file. You can enter any valid commands that are supported by the operating system in which EPX is running.
The Windows example below uses a script file and two batch files. As a customer’s name is passed through the Command Line BIC activity, their name is placed in a file with a unique filename (the customer’s name). A directory bearing the customer’s name is then created and the file containing the customer’s name is moved to the new directory. For the following example, the customer’s name is Mike Johnson.
The sample script file contains the commands:
echo SET
CUSTOMER=%LastName%_%FirstName%>c:\docs\customer.bat
echo %FirstName% %LastName% > c:\docs\customer.txt
copy c:\docs\customer.txt
"d:\data\customers\%LastName%_%FirstName%.txt"
c:\docs\changedir.bat
- The script file first creates a batch file in c:\docs named customer.bat, which will be called in a moment. The batch file will be used to create a system variable called CUSTOMER, which will represent the customer’s name in the format LastName_FirstName. (Executing a SET command directly from the script does not create a system variable.) For customer Mike Johnson, the batch file contains the command SET CUSTOMER=Johnson_Mike.
- The batch file then writes the name “Mike Johnson” to the file c:\docs\customer.txt. This file is for temporary use and is overwritten every time the Command Line BIC activity passes a new customer name.
- The script copies the contents of customer.txt as a new file, d:\data\customers\ Johnson_Mike.txt. (Here, d:\data\customers is a pre-existing directory.)
- The script file then executes the batch file c:\docs\changedir.bat.
- The changedir.bat file first calls the customer.bat file that was created in the script. The customer.bat file executes, creating a system variable called CUSTOMER with a value of “Johnson_Mike”.
- The changedir.bat changes the current drive to d:, and then changes the current directory to d:\data\customers.
- The batch file now creates a new directory under d:\data\customers, called \Johnson_Mike.
- Then, the batch file moves the file Johnson_Mike.txt from d:\data\customers (the destination to where it was copied by the script) to d:\data\customers\Johnson_Mike.
The task performed in this example now requires a directory change. However, changing directories is not allowed in scripts executed by the Command Line BIC, so the command to change directories is executed via a batch file (as are the remainder of the commands in this task).
The sample batch file, changedir.bat, contains the commands:
CALL c:\docs\customer.bat
d:
cd data\customers
md "%CUSTOMER%"
move "%CUSTOMER%.txt" ".\%CUSTOMER%\%CUSTOMER%.txt"
Notes on Creating Command Line BIC Script Files
Before writing script files for use by the Command Line BIC, you should be aware of the following:
- The local directory is always the directory of the BIC Manager’s application server. If EPX is installed to the default Windows directory, then the local directory is C:\Enterworks\EPX\tomcat.
- If you want to use existing system variables in the script file, you must prefix the percent sign (%) with a carat (^) — e.g., ^%TEMP^% — as the script file uses the percent sign to define internal parameters. Also, as indicated in the earlier script example, you cannot define a system variable from within a script.
- You cannot change directories from within a script. Any commands to change directories must be executed from a batch file, as shown in the previous example.
- For directory names and file names that include spaces and more than eight characters, you must enclose the path with opening and closing quotes. See the sample string and batch file contents for examples of this.
- If your script writes a file that you want to preserve, you must include a string giving the new file a unique name. Otherwise, each time the process flow is started, the previous file will be overwritten. You can use any replaceable parameter that returns a unique value. You can also have the option for EPX to create a unique name for each file by using the system parameter %sys.workitem.version.uid%.