Var search
This block is used to check if this variable exists. This block has two outputs: ‘Found’ and ‘Not found’, and therefore two paths of a scenario.
This block has the ‘Variable’ and ‘Nested object’ fields. When an embedded object is specified the system will check if the object exists in the variable’s data structure. (More details about an embedded object you can find in the ‘Variable’ block).
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.