Conditional Logic Macro Function¶
Conditional logic in macros is supported by the fn.conditional_logic
function that takes
two parameters:
- the name of an instance of the
data/ConditionalLogic
data model - a value that serves as input to
data/ConditionalLogic
the data model.
The namespaces that can be used as left_expression
values in the data model can depend on
the reference to the data model in a Provisioning Workflow. The namespaces - that can also
be referenced in full - include:
{{self}}
{{previous}}
{{input}}
{{cft}}
{{pwf}}
Consider the following example data/ConditionalLogic
data model
called “Is_SLC_Allowed”:
"conditions": [
{
"unary_operator": "NOT",
"right_expression": "{{ logic.DATA }}",
"conditional_operator": "AND",
"condition": "contains",
"left_expression": "{{ pwf.SLCS }}"
},
{
"unary_operator": "NOT",
"right_expression": "{{ input.CURRENT_SLC }}",
"conditional_operator": "AND",
"condition": "containsStartOf",
"left_expression": "{{ logic.DATA }}"
},
{
"right_expression": "{{ input.CURRENT_SLC }}",
"condition": "containsStartsWith",
"unary_operator": "NOT",
"left_expression": "{{ logic.DATA }}"
}
]
Also suppose the Provisioning Workflow for this example has a list variable SLCS
and receives an input.CURRENT_SLC
value.
Furthermore, during the call of the fn.conditional_logic
function in the
Provisioning Workflow, it receives a scalar value as an argument, for example:
{{ fn.conditional_logic Is_SLC_Allowed,128 }
- The scalar value reference
{{ logic.DATA }}
can be ommitted from eitherleft_expression
orright_expression
. Its reference is then assumed. - The input value is referenced as
{{ input.CURRENT_SLC }}
- The list that is the Provisioning Workflow variable, is
{{ pwf.SLCS }}
As another example, consider a data/ConditionalLogic
model called “TestData”
with three conditions:
"conditions": [
{
"conditional_operator": "OR",
"left_expression": "{{input.DATA}}",
"condition": "contains",
"right_expression": "AAA"
},
{
"conditional_operator": "AND",
"left_expression": "{{input.DATA}}",
"condition": "contains",
"right_expression": "BBB"
},
{
"left_expression": "{{input.DATA}}",
"condition": "contains",
"right_expression": "CCC",
"unary_operator": "NOT"
}
The following function checks if a received input value “AAAaaaBBBaaaCCc” fulfills the condition: contains “AAA” OR “BBB” AND NOT “CCC”, as in the macro test using a scalar value:
{{ fn.conditional_logic TestData,AAaaaBBBaaaCCc }}
The condition resolves to true.
Finally in the following example, the conditional function is used as a condition in a Provisioning Workflow. The Data Model instance of data/ConditionalLogic called “Does Newland Exist” tests a single string matching condition:
"data": {
"conditions": [
{
"right_expression": "Newland",
"condition": "isexactly",
"left_expression": "{{pwf.EXIST}}"
}
],
"name": "Does Newland Exist"
}
The Provisioning Workflow step to apply a Configuration Template if the condition is false.
So the step is carried out only if there is not already a country_name
called “Newland”.
"workflow": [
{
"templates": [
{
"conditions": [
{
"condition": "(( fn.conditional_logic \"Does Newland Exist\" == False ))"
}
],
"template": "CFT1"
}
],
"entity": "data/Countries",
"set_list": [
{
"set_var_name": "EXIST",
"set_var_value": "{{data.Countries.country_name|country_name:Newland}}"
}
],
"method": "add",
"entity_type": "model"
}