Var search
The “Variable Search” block checks whether a variable exists. This block always has two outputs: Found and Not Found. Consequently, there are two possible paths for the scenario to proceed.
The properties of this block include the fields “Variable” and “Nested Object.” If a nested object is specified, the block will check for the existence of a specific object within the variable’s data structure (For more information about nested objects, see “Variable“).
For example, if you want to extract data from JSON, you need to pass this data into the “Nested Object” field. For instance, if a user provides a phone number, and you need to retrieve it in international dialing format, you should specify ‘phone’ in the “Nested Object” field of the “Variable” block.
Scenario example:
To search in an array that comes, for example, from an HTTP request (which is saved and stored in a variable, such as var1):
[
{
"name":"Ford",
"val":"John",
"price":"1000",
"cars":[ "Ford", "BMW", "Fiat" ]
},
{
"name": "BMW",
"val":"Jack",
"price":"2000",
"cars":[ "Ford", "BMW", "Fiat" ]
},
{
"name": "Fiat",
"val":"Nik",
"price":"3000",
"cars":[ "Ford", "BMW", "Fiat" ]
}
]
To find the “Fiat” cars, you need to specify the following in the script fields:
var1[0].cars[2]
To do this, you need to specify in the fields:
- Variable: var1
- Nested object: [0].cars[2]
This will create the element of the array var1[0].cars[2].
This block can be used before the “Variable” and “Variable Analysis” blocks to have the system check the variable’s existence before assigning a value to it.