Host Automation Object Samples


Sample JScript Script

This script is designed to be used with BlueZone for the Desktop.  The script will launch an already existing BlueZone iSeries (AS/400) configuration called "iseries.zad", navigate to the End User's Job Log, and write the contents of the Job Log to a file and store it in the following location:

C:\JOBLOG.TXT

 

To modify and use the script, create a text document, name it anything you wish, and save it with a .js file extension.  Copy and paste the entire script into the document you just created.  Copy the script into the BlueZone \scripts folder.

Launch the BlueZone Script Host and Debugger program.  Select File:Open from the MenuBar.  Locate the script you just created and highlight it and click the Open button.  The script will now be presented in the BlueZone Script Host and Debugger main window.

In order for the BlueZone Host Automation Object to communicate with a BlueZone Display emulation session, you must enable BlueZone's DDE interface.

Create a BlueZone configuration that will connect to your iSeries host and be sure to enable the DDE interface.  name it "iseries.zad".  Replace "username" and "password" in the script below with a valid username and password.

SEE  Configuring BlueZone to Work with the Host Automation Object

Sample Script

 

// Sample JScript using BlueZone Host Automation Object

 

// This sample script will run a BlueZone session and then

// logon to an iSeries host and write the Job Log to the disk

// file C:\JOBLOG.TXT.

 

// Instantiate a handle to BlueZone Host Automation Object

host = new ActiveXObject( "BZWhll.WhllObj" )

 

// Run BlueZone iSeries Display with session ID of S1

// Timeout and return error if no signon screen after 30 seconds

// Continue with script execution after host sends 1 screen paint

 

ResultCode = host.OpenSession( 1, 1, "warrenton.zad", 30, 1 )

  if ( ResultCode != 0 )

host.MsgBox( "Error connecting to host!", 48 )

 

// connect to session with hllapi id of "A"

// return error if session not found

 

else

 

ResultCode = host.Connect( "A" )

  if ( ResultCode != 0 )

host.MsgBox( "Error connecting to session A!", 48 )

 

// logon to host then wait for host to unlock the keyboard

host.SendKey( "bcampbell@Tb1495c@E" )

host.WaitReady( 10, 1 )

// go to Display Job Log screen

host.SendKey( "1@E" )

host.WaitReady( 10, 1 )

host.SendKey( "1@E" )

host.WaitReady( 10, 1 )

host.SendKey( "10@E" )

host.WaitReady( 10, 1 )

 

// create disk file C:\JOBLOG.TXT

// the text file will be created in the folder where the script is run from

 

var ForReading = 1, ForWriting = 2, ForAppending = 3

var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

var fs, f, ts

 

// create the joblog file

fs = new ActiveXObject( "Scripting.FileSystemObject" )

fs.CreateTextFile( "_joblog.txt" )

f = fs.GetFile( "_joblog.txt" )

ts = f.OpenAsTextStream( ForWriting, TristateUseDefault )

 

// read the screens until "Bottom" is found at position row 19, column 74

var MoreText = "More.."

var BottomText = "Bottom"

var i, Buf

if ( MoreText != BottomText )

   i = 1 - 24

      host.ReadScreen( Buf, 80, i, 1 )

 

// write the job log screens to disk

   ts.Write( Buf )

   ts.Write( " " )

   host.ReadScreen( MoreText, 6, 19, 74 )

 

// close the file

ts.Close( )

 

// logoff from host

host.SendKey( "@E" )

host.WaitReady( 10, 1 )

host.SendKey( "@3" )

host.WaitReady( 10, 1 )

host.SendKey( "90@E" )

host.WaitReady( 10, 1 )

 

// close BlueZone iSeries Display having session id of S1

host.CloseSession( 1, 1 )