Use variables in scripts
BlueZone Scripts support the ability to create up to four variables that can be utilized in a BlueZone script.
There can be many uses for variables. For example, if you want to create a BlueZone script (.bzs) to automate the log on process for several host systems, or log on to several sessions on the same host, you can create a BlueZone script with a variable for user name (InputStr1) and a variable for password (InputStr2) by using BlueZone's "Input" script event. Then the script passes the values of InputStr1 and InputStr2 to additional host sessions through BlueZone's command line switch feature and uses the stored values to automatically log on to additional hosts.
BlueZone script exercise
The following BlueZone scripting exercise assumes that you are already familiar with BlueZone and somewhat familiar with BlueZone scripting.
This exercise creates a BlueZone script that prompts the end user for user name and password, then uses the values of user name and password to log onto an iSeries host. Then, the script automatically launches a second iSeries host session and passes the values of user name and password to the second iSeries host session. A script automatically runs on the second iSeries host which uses the values of user name and password to log onto the second host.
By using this technique, the end user is prompted to enter their user name and password only once, at the very beginning of the script, and the script inserts the user name and password values at the correct point for each host.
Preparing two BlueZone iSeries Display sessions
1. Launch two BlueZone iSeries display sessions.
2. Configure the sessions to connect to the same or two different iSeries hosts.
3. Save the first session to a file called session1.zad.
4. Save the second session to a file called session2.zad..
Creating the first BlueZone script
1. Launch the BlueZone Script Editor and start creating a new script as follows.
2. In the Script Events list, double-click the Input event.
The Input dialog opens.
3. Type InputStr1 in the Title field, followed by the text that you want to appear when the end user is prompted. For example, type Enter your user name.
Image
4. Click OK to enter this event into the script.
5. Repeat the process to create an input box for the end users password as shown here. For the password event, check the Hide Input as User Types check box.
Image
6. Click OK. So far, your script looks like this:
Image
7. In order to send the value of InputStr1 to the host, use the Type event. In the Script Events list, double-click the Type event.
The Type dialog displays.
8. Type InputStr1 and click OK to add it to the script as shown above.
9. The next step in the log on process is to send a Tab function. This advances the cursor to the Password field.
a. To add a Tab to the script, in the LU Functions list, double-click the Tab / Field Advance function.
This adds the Tab / Field Advance function to the script.
10. The next event is to pass the value of the end user's password. This is accomplished by sending a Type InputStr2 to the host, in the same way we sent the value of user name above.
a. In the Script Events list, double-click the Type event.
The Type dialog displays.
b. Type InputStr2.
c. Check the Encrypt and Hide check box.
d. Click OK to add it to the script.
11. The final step in the log on process is to send an Enter function. This completes the log on sequence:
a. In the LU Functions list, double-click the Enter function.
The Enter function is added to the script.
12. Launch a second iSeries display session. This is accomplished by using the Run event. We will create a Run event that calls the correct program, and uses command line switches to set the configuration file to use, and to pass along the InputStr1 and InputStr2 values to the second iSeries session.
13. In the Script Events list, double-click the Run event.
The Run dialog displays.
14. Type the following in the command line:
C:\Program Files\BlueZone\BZAD.EXE /Fsession2.zad /1InputStr1 /2InputStr2
15. Click OK to enter this event into the script.
This command line launches a BlueZone iSeries display session, use the configuration file named session2.zad, and send the values of InputStr1 and InputStr2 to the new iSeries session.
16. Click OK.
17. Save the script and name it script1.bzs.
So far, we have created a script that prompts the end user for user name and password, automatically logs on to an iSeries session using the stored values of user name and password, and automatically launches a second iSeries session.
The next step is to create a second BlueZone script that uses the values of InputStr1 and InputStr2 from the first script, to automatically log on to the second iSeries host.
Creating the second BlueZone script
1. Create a second BlueZone script by selecting New from the BlueZone Script Editor menu.
You now have a blank screen in which you can create a new script.
2. It is recommended to start with a Wait event in order to give the new session some time to bring up the main log in screen.
a. In the Script Events list, double-click the Wait event.
b. Type the number of seconds to wait. For example, 2.
c. Click OK.
3. Add a Type event:
a. In the Script Events list, double-click the Type event.
The Type dialog displays.
b. Type Var1.
c. Click OK to add this to the script.
So far, your script looks like this:
Image
4. In the LU Functions list, double-click the Tab / Field Advance function.
5. Add a Type event:
a. In the Script Events list, double-click the Type event.
b. Type Var2.
c. Click OK.
6. In the LU Functions list, double-click the Enter function.
Your script now looks like this:
Image
7. Save this script and name it script2.bzs.
You must now configure the second iSeries session to automatically launch this script upon connection to the host, which uses the value of Var1 for the user name, and the value of Var2 for the password.
Note
Var1 relates to the \1InputStr1 and Var2 relates to the \2InputStr2 that is used in the command line switch that launched the second iSeries display session.
Configuring the second iSeries session to automatically launch Scritpt2.bzs
1. Launch the second iSeries display session.
2. Click Script Properties from the BlueZone menu bar.
3. Check the Auto-Play Script on Connect check box.
4. Click Browse.
5. Select the script2.bzs file and click Open.
6. Click OK to exit this dialog.
7. Save the iSeries configuration. Make sure you save it as session2.zad.
Testing the script
At this point you are ready to test the completed script.
1. To test the script, start the first iSeries session and connect to the host.
2. Click Script Play from the BlueZone menu bar.
3. Select the script1.bzs file and click Open.
The script immediately starts running. The Enter Username dialog opens:
Image
4. Type your user name and press the Enter key.
The Enter Password dialog opens:
Image
5. Type your password and press the Enter key.
The script continues to run and you are logged onto the host. Then the second iSeries session launches and you are logged onto the second host.
Tips
You can assign the script1 to a BlueZone power key which makes it much easier for the end user to launch a script. Refer to Mapping scripts to power pads for more information.
You can adjust the speed of the script playback. When you are developing a script, sometimes it's helpful if the script runs at a slow speed so you can see exactly what is happening.
Speed up the script and turn off the Script Status Window. Once the script is completely debugged and working properly, you may want to speed up the script execution speed and also turn off the Script Status Window. This is done by selecting Script Properties from the BlueZone menu bar and making any desired changes. Refer to Script properties for more information.