Saflet101IfThen
If/Then Structure
The IfThen ActionStep evaluates a true or false condition and takes the corresponding path.
Walkthrough
For this walkthrough; you will need to be connected to a SafiServer (see Connection to SafiServer from SafiWorkshop). You will also need to create a Project/Saflet with the Custom Initiator selected as the starting initiator (See: Creating a Project and Saflet)
Add an Assignment and an IfThen ActionStep to your Saflet (click the ActionStep in the pallet and then click the work area):
Double-click Assignment step to bring up edit dialog. In this example we have already created the variable varA. Assign the value of 5 to the variable varA:
Next, double-click the IfThen ActionStep to bring up edit dialog:
Click edit button for the Boolean field (the "..." button) will bring up Dynamic Value Editor with the Bool Expression tab selected. This editor will help you create an expression that will return a true or false value.
There are three ways in which you can return a boolean value:
- Variable Tab: Assign boolean variable.
- Script Tab: Write a script that returns a boolean
- Bool Expression Tab: Use boolean expression editor to return true or false
Choose varA as the Left Operand and select the Literal option button and enter a value of 5 for the Right Operand. Select the == as the Operator. We know this expression should resolve as true because we assigned the value of 5 to varA in the Assignment ActionStep. Now Click the Set Expr button to add the expression:
Press OK and OK
Now add in a couple DebugLog steps and make the message in one "true path" and the message in the other "false path". Attach each of these steps to the corresponding IfThen outputs:
Save you Saflet and Publish it to your SafiServer.
We can now debug the Saflet to verify what path the Saflet takes. Press the debug button and use the Custom Initiator Launcher to initiate the Saflet:
Stepping through the Saflet you should see it take the true path
Now, change Assignment step value to 10:
Press OK, save the Saflet and Publish it to the server.
Instead of debugging, this time we'll use the Console to verify the results. Open the Custom Initiator Launcher and initiate the Saflet. You should see the following outout in the console:
SideBar
User Login
Comments (