Self Service Lab - Expressions and Operators
Overview An "expression" is a piece of code that evaluates a variable to a particular value. Any code snippet that evaluates to a value is an expression. Expressions in Pliant are used to manipulate data, take inputs, provide data to and from blocks, and provide output. An "operator" is used to compare one value to another. Arithmetic operators include identifying if values are greater than, less than, or equal to each other.
String operators include identifying if strings are equivalent, or equal length, and other similar features.
Operators can be strung together using "AND" and "OR" statements.
Expressions
Sample Expressions:
1
1 + 1
$FirstName + $LastName
$Number * 6
$Number > 14
Operators
The basic operators in Pliant are "equal to," "greater than," "less than" and other similar features.
Sample Operators:
"1 == 1" meaning "1 is equal to 1"
"2 > 1" meaning "2 is greater than 1"
"2 >= 2" meaning 2 is greater than or equal to 2"
By combining variables, expressions, and operators, values can be modified as needed for output. Sample Conditional Operators and Expressions
Availability = 95
AvailabilityTarget = 99.999
AvailabilitySuccess = ""
All screenshots in this article are showing Pliant Dark Mode. Check out the Color Scheme switcher in the top right corner of the Pliant interface
The two IF statements can also be combined into an if/else statement:
Launch Lab: Click here to get a lab login where you can try the following procedures
A. Create a flow that outputs the result of a conditional operator
This will explain how expressions and operators are used in pre-defined blocks.
A1: Create a new flow. Name it "Expression"
A2: In the Start block, add two new variables, ValueA and ValueB:
A3: Clone the "Assign" block to get a second one:
A4: Edit the first block with the variable $ValueA and value of 43. Edit the second block with the variable $ValueB and a value of 88. Note that in this example the values of 43 and 88 are not enclosed in quotation marks as they are of "integer" type, and not "string".
A5: Using the Blocks Palette on the right of the screen, browse to the "Common" tab and scroll down to the "If" block. Drag the block beneath the Start block.
The "If" block allows for a condition to be evaluated. If the condition evaluates to "true" then the blocks immediately following are then run; if the condition evaluates to "false" then the blocks within the "Else" branch are run.
Populate the Condition field with the following: $ValueA > $ValueB. This evaluates the condition "If $ValueA is greater than $ValueB".
A6: Drag an "Assign" block immediately beneath the If condition. Populate it with the following parameters:
A6: Drag an "Assign" block beneath the "Else" portion of the If block and fill with the following parameters:
A7: Save and Run the flow. Note the results at the bottom of the page.
Note the result: "ValueA is not greater than ValueB" correctly interprets ValueA, 43, as less than ValueB, 88.
Change the values of ValueA and ValueB, save, and run the flow several times to examine how the expression and operators work.
B. Create a flow that uses an expression to add two variables together and an operator to compare the results.
B1: Create a new flow. Name it "Expression Two"
B2: Expand the "Advanced" pulldown on the Start block to start creating variables. Create four variables with the following parameters:
B3: Drag three Assign blocks into the flow and populate the three Value variables with the following parameters:
B4: Drag an If block into the flow and fill with the following condition:
B5: Drag Assign blocks into the If and Else portions of the If block and assign values as follows:
Assign if true: "The sum of " + $ValueA + " and " + $ValueB + " is greater than " + $ValueC
Assign if false: "The sum of " + $ValueA + " and " + $ValueB + " is not greater than " + $ValueC
B6: Save and Run the flow. Note the "result" at the bottom of the page. Modify the values of the three variables and re-run to see how the If condition chooses the correct path.
C. String Expressions
Expressions and Conditions can also be performed on string values. This lab exercise will explore various string expressions. The Pliant "Assign" block can be used to perform expressions and functions on strings.
C1: Create a new flow. Name it "ExpressionThree"
C2: In the Start block, add a new variable called “mystring”, give it a default value of “A random string” and flag it as output:
C3: Change the initial Assign block so that Value is $mystring.length
C4: Save and Run the flow. Note the output in the results field. It will show the length of the string
C5: Change the value of the Assign block to use the “slice” JavaScript method
C6: Save and run the flow. Note the results of the slice expression
D. Expressions in other blocks
So far we have looked at using methods and expressions within "Assign" and "If" blocks. Methods and expressions can be used in other Blocks as well. This exercise shows how.
D1: Create a new flow. Name it "ExpressionFour"
D2: Drag an HttpRequest block into the flow as the first block. Configure with the following Parameters
Method: “GET”
Host: “http://quotes.stormconsultancy.co.uk/random.json”
If this is the first time seeing the HttpRequest block, for purposes here this block is simply performing an HTTP "Get" request on a URL.
The URL that we have chosen to put in the Host field will provide a random quote and return it in json format.
D3: Expand the "Output Parameters" pulldown in the HttpRequst block
D4: Edit the "Assign" block with the following parameters, using the Autocomplete to help find the parameter names
D5: Save and Run the flow. The resulting output will show how the HTTP response is formatted. You will see output similar to the following:
D6: Delete the 'value' information in the "Assign" block. Replace it with the following:
"The quote, '" + $HttpRequest_1["result"]["quote"] + "', is " + $HttpRequest_1["result"]["quote"].length + " characters in length and is attributed to " + $HttpRequest_1["result"]["author"] + "."
D7: Save and Run the flow. Note the output. Expressions can be placed into any block with a 'function' field: