BinaryDecision Use Examples
Binary Decision is mainly used to compare two values. It performs a test which is determined by the the input and outputs either “True” or “False”. This directs the process flow either to the right or down depending on the result of the test.
Simple Binary Decision Use
In this process, we are using GetRequestAttributes to return the page we are on. ToLower converts the entire string to lowercase so we can do our comparisons entirely in lowercase. The binary decision is used to determine if we are on the default page, “default.aspx”. If we are, then we hide sections. If not, the process ends without any further action.
Here is a closer look at that binary decision. We are comparing the output from the ToLower service with the hard coded value “default.aspx”.
‘Type’ is set to ‘String’ because the right clause is a string and should be encased in quotations. The operator is set to “=” because this is the comparison we want to perform.
Note: the left clause is always treated as a variable. If you wanted it to be a string, you must add your own quotation marks.
Here is the Binary Decision Test that is performed:
Typically this is how that string is broken down into the Binary Decision inputs:
The binary decision logs display the node set referenced in the left clause and does not replace it out for the value used. So, in our example, we can look at the output returned from WorkData/ToLower/OutputString and see its value is not equal to “default.aspx”:
“purchaseorders.aspx” is returned by the “ToLower” Service, so the result of the Binary Decision is “False”. As a result, the process flow is directed to the right and the process is terminated.
Within a “For Each” Loop
In this process we have an inquire service, “GetUserId”, which retrieves all the User Ids.
Then, we’re looping over the results, and comparing it with a field value.
If a Match is found, we are displaying a popup message using “SetWindowAttributes” service. If a match is not found, we’re continuing with the loop iteration and finally ending the process using “Terminate” service.
This is the “BinaryDecision” service in which we are comparing the UserId retrieved by “GetUserId” service to the “UserId” field on our webpage.
We have “=” as the operator and “String” as the data type for this comparison. Note: The Index of the loop is automatically handled by EASYProcess.
This is the output returned by the Binary Decision service. Notice the “[$Index0]” has been automatically added to reference the correct GetUserId node which matches the current iteration of the “For Each” Loop.
Within a Binary Decision
Many tests can be added to a Binary Decision and they can be separated within the test via AND or OR. When looking at a complicated Binary Decision Test you should split on the ORs and consider everything between them in parenthesis
ANDs are always evaluated before ORs, so we can group like so:
Here is the test formed by the logic above:
WorkData/Input/CartId and WorkData/Input/CartId != ''
WorkData/Input/Id and WorkData/Input/Id != '' and WorkData/Input/Verb != 'DELETE'
WorkData/ShoppingCartItem/CartId and WorkData/ShoppingCartItem/CartId != ''
There are some examples that are difficult to express in Binary Decisions which use parentheses in order to evaluate ORs first. In these examples, we can convert them to be logically equivalent and evaluate ANDs first.
Within an Evaluate
Often times the logic within a binary decision can get complicated and if you would prefer to do all logic in XSLT, you can use an evaluate with a binary decision to accomplish the same task.
Here is the above logic regarding CartIds passed in. The logic’s purpose was to determine if the CartId was passed in and useable (not blank).
The process canvas will look like an evaluate (containing all the logic) and a binary decision (checking the result of the logic against an expected value). This allows us to use XSLT Ifs and Chooses which can simplify complex logic.
Comparing Numeric Values
A common use for binary decision is to check NoOfRecords returned from a query. For instance we could query to find out how many lines your cart currently has. The following binary decision could be named “Cart Has Items?” and have the test “WorkData/Inquire/NoOfRecords > 0”.
Here is how we would set up that binary decision:
There are actually many tests that can answer the question if the cart has items, but some may capture too narrow of a success window.
Make sure to use the Int type when dealing with numbers. In our example, there is no way for the result to be a decimal, but other cases may result in 0.00 which is not equal to 0. If we are querying for the shipping cost of a cart and the result is 0.00 and we have a binary decision checking for the string “0”, the result will be “False”. It is a good idea to get in a habit of using Int when dealing with numbers.
Checking for True/False Flags
Another common use of binary decisions is to compare a node-set Variable to an expected value (True/False).
Here is how we set up the Binary Decision:
It is a good idea when doing logic like this to protect against various letter cases (TRUE, True, true). This is especially a good idea when the value passed in comes passed in from another process or an API call.
In order to safeguard against this, you can use the EASYProcces ToUpper function.
Using the Left Clause Without a Node-Set Variable
The left clause is always treated as a variable, meaning no quotation marks are added and you cannot select the Type. If you wanted it to be a string, you must add your own quotation marks.
Binary Decision Logs:
You could also use the left clause as an int. Since quotation marks are not automatically added, if the value in the left clause is not a node-set variable, it would be treated as an int.
Binary Decision Logs: