Upgrade 3CX to v18 and get it hosted free!

set variable

Author image
Usage: SET VARIABLE <variablename> <value>

These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary. Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted and any variables in that channel are deleted as well.

Just like get variable, this works for writing to functions too.

Returns:
200 result=1

NOTE: currently (*version<= 1.2.11) the value cannot contain spaces. Putting quotes or double quotes around the value won’t work. Workaround is to change spaces to e.g. underscores. In unix sh this would be something like : echo “part1 part2” | tr ‘ ‘ ‘_’

Using Asterisk Version 1.12.1 you should use the escape characters to set the variable correct. Something like: “SET VARIABLE TEST \”hello again\” \n”);

Passing variables as a value of another variable

Variables such as channel variables set as a value for another variable should be replaced by the actual value for it will be read as a string.
This example won’t work if issued to Dial command

  SET VARIABLE MY_DIALSTRING "ZaP/g1/${EXTEN}"

The ${EXTEN} variable should be replaced by the actual dialed number. eg 12345678

  SET VARIABLE MY_DIALSTRING "ZaP/g1/12345678"

in extensions.conf

  exten => s,1,Dial(${MY_DIALSTRING})

Go back to Asterisk AGI

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.