The WhenState setting determines when real actions occur--see the Understanding States section for a description of "formal states" that are set by the framework depending on the active connection status.
The WhenState setting is simple--it checks for a specific state either set by the framework (a formal state) or by the SetState action setting.
The catch-all state is the asterisk rather than a state text name and when used should be the last state tested for, since it will always run!
Once the initial screen is displayed, if the script continues (no "Exit" set with SetState), the logic that executes can be differentiated by adding a ".In" to the state name. If the .In is there, the logic runs after the user has entered the active screen. If you want logic to run both on display of a screen and input, the .In variant should be before the unqualified otherwise it will never run.
This example is from the AS400 Generic ID sample--in this sample the SSO scripting is running until the user signs off and the Signon Screen reappears. It demonstrates checking for specific states and includes a catch-all * state:
ScreenName=Signon
Recog=1,36,Sign On
WhenState=Logon1
PutScreen=HostID,2,22
PutScreen=HostPW,3,22
Enter=[enter]
SetState=Logon2
WhenState=* #If return to signon, get-out which will alert parent
Disconnect=Yes
SetState=Exit
This example shows formal state Logon1 (Credentials were read) along with use of the .In qualifier to capture user entries of the HostID and HostPW:
ScreenName=Signon
Recog=1,36,Sign On
WhenState=Logon1
PutScreen=HostID,2,24
PutScreen=HostPW,3,24
Enter=[enter]
SetState=Logon2
WhenState=Logon2 # Means an error
GetMessage=24,1,80 # Display to User
SetState=Exit # And end logic
WhenState=Capture.In # User has entered HostID and HostPW
SetField=HostID,2,24
SetField=HostPW,3,24
SetState=CapturedPW # Flag for later use
WhenState=Capture # Outbound from host
PutScreen=userHostID,2,24 #in case entered...
The WhenState setting contains the following action settings associated with the detected State:
•SetState Action - Set the Active State used for the WhenState Logic
•PutScreen/SetScreen Action - Set a Field or Text Expression into the Screen
•Enter Action- Enter the Screen
•SetField Action - Set the Value of an Active Field / Variable
o@GenPW Function - Generate a complex password
•SaveCredentials Action - Save Credentials captured with the SetField Action
•Disconnect Action - Disconnect the Session
•GetMessage Action - Read a Message from the Screen