Copy variable

The Copy a variable component copies the value of one variable to another. It can combine two lists or objects.

Configure the component

  1. In the "From" field, enter the name of the variable from which you want to copy the data.
  2. In the "To" field, enter the name of the variable to which you want to copy the data.
  3. If you need to combine the data from the "From" field with the data in the "To" field, check the "Merge" checkbox. This only works for objects and lists.
Provided that the variable specified in the "From" field does not exist in the bot, the null value will be written to the variable specified in the "To" field after copying. If there is no variable where copying is done, the variable will be created and its value will be the same as in the variable from the "From" field.

If you do not include the "Merge" checkbox when copying a variable, the value of one variable is simply copied to another. Only the copied value will be in the variable after copying, the old value will be replaced with it.

For example, there are two lists in the bot.

In the variable var1 there is such a list:

[
"apple",
"pear",
"kiwi"
]

In the variable var2 there is another list:

[
"strawberry",
"lemon",
"mango"
]

Copy the list from the variable var1 to var2 without merging objects.

Save the changes, then go to the "Users" section‎. If you open all the user variables, you can find that the value in the variable var2 has become exactly the same as in the variable var1, from where the value was copied.

If you need to merge data from the field "From" with the data located in the "To" field, you need to mark the Merge checkbox.

Example:

After copying, all the values from var1 and from var2 appeared in the list of the variable var2:

As you can see from the example, in the case of copying objects or lists with an active Merge checkbox, the elements from the variable "To" will be displayed at the beginning of the list, and the elements from the variable "From" will be at the end of the list. This happens without activation of the reverse merging.

However, if the Reverse Merging function is active together with the Merge checkbox, the list or object will be merged in reverse order: elements from the variable From will be displayed at the beginning of the list, and elements from the variable To will be displayed at the end of the list.:

If there are numeric keys in the object, the numeric keys will always be at the beginning of the object while copying a variable. This is a feature that you have to put up with when merging objects.
To the beginning ↑