<< Click to Display Table of Contents >> Navigation: Several practical recommendations > Using Variables in Tasks > Prefixes Used with Variables |
Prefixed can precede the name of a variable beginning with version 8.1.
There are 2 kinds of prefixes:
•Context prefix
•Protocol prefix
Context prefix
A context prefix can have 2 values: local or global
A prefix precedes the name of a variable and ends with the "@" symbol. It is not case-sensitive.
For example:
local@MyVar
global@userinfo
When a context prefix is not specified, the general rules of visibility described in the chapter "Rules for Using Variables in Expressions" (see "The rule of visibility") apply.
Protocol prefix
Only one protocol, JSON, is currently used. A protocol prefix ends with a colon ":"
For example:
json:userinfo.name.firstname
If a protocol prefix is not used, this means that we are using the value of the variable entirely as it is. We either extract it while reading or write the specified value.
A json prefix means that the userinfo variable should be processed as a JSON object and the value at the name.firstname destination should be extracted from it.
If you use this expression to write to a variable, RoboTask will accordingly write to the userinfo variable the value specified at the name.firstname destination as to a JSON object.
If you attempt to read just the value of the userinfo variable without prefixes, RoboTask will return the JSON object entirely in the form of a string.
For example:
{"name":{"firstname":"John","surname":"Dou"},"address":"New York, 5-th ave,125"}
Please note that the path to the value in the JSON object is case-sensitive. This is a JSON standard. In other words, the expressions
json:userinfo.name.firstname
and
json:userinfo.Name.Firstname
are different expressions that can contain different values.
In this way, the JSON format allows storing structured data and arrays of values.
We will skip the format description. For more information, go to the article: https://en.wikipedia.org/wiki/JSON
Use of Prefixes
Prefixes can be used in any sequence in front of the name of a variable. Both prefixes can be used at the same time.
For example, the expressions
local@json:userinfo.name.firstname
and
json:local@userinfo.name.firstname
have the same meaning.
If you specify a wrong prefix, RoboTask will treat this sequence of characters as a part of the variable name and you will most probably get an error message.
Related Topics
Saving of a result into a variable
Rules for using variables in expressions