Quantcast
Channel: VOIP-info.org Wiki Changes
Viewing all articles
Browse latest Browse all 5767

Asterisk cmd Set

$
0
0

Synopsis

Sets variable to value

Version differences:
This command is not available in Asterisk 1.0.9. Use SetVar instead.
As of v1.2SetVar is deprecated and we are back to Set.
As of v1.4 the use of Set() to set multiple variables at once and the g flag have both been deprecated. Please use multiple Set() calls and the GLOBAL() dialplan function instead.
As of v1.6 only if you have a corresponding "compat" setting, then Set() does not strip surrounding quotes from the right hand side as it did previously.


Description


Set(variablename=value|options]) (starting with Asterisk 1.4)
Set(variablename=value[|variable2=value2][|options]) (up to and including Asterisk 1.2)

This application can be used to set the value of channel variables or dialplan functions. It will accept up to 24 name/value pairs upto Asterisk 1.2, but only one name/value pair in Asterisk 1.4 or later.
When setting variables, if the variable name is prefixed with _ the variable will be inherited into channels created from the current channel. If the variable name is prefixed with __ the variable will be inherited into channels created from the current channel and all children channels.
Next to the Set() command there is also the SET function available.

Options for Asterisk 1.2 (and possible earlier versions)

  • g: set a global variable (valid in the entire dialplan, not just the channel)


As of Asterisk 1.4 the correct syntax to set a global variable is like this

exten => 100,1,Set(GLOBAL(FOO)=456)

extensions.conf:
; If clearglobalvars is not set, then global variables will persist
; through reloads, and even if deleted from the extensions.conf or
; one if its included files, will remain set to the previous value.
;
clearglobalvars=no

Asterisk 1.6

Note that Set() changes behaviour in Asterisk 1.6 which can be controlled via asterisk.conf:

[compat]
app_set=1.6

If (and only if), in /etc/asterisk/asterisk.conf, you have a [compat] category, and you have app_set = 1.6 under that, then the behavior of this app changes, and does not strip surrounding quotes from the right hand side as it did previously.

Example

Set(numTries=4)
Set(CALLERID(number)=000000)
Set(CALLERID(name)="The Name")
Set(NIGHTMODE=1,g) ; set a global variable

To increment a variable, you can use:

Set(total=$[${total} + 1])

To set inherited variable:

Set(_CALLID=${UNIQUEID})
Set(__CALLID=${UNIQUEID})

NOTES:
  • Variable names are not case sensitive.
  • Each channel gets its own variable space. There is no chance of collisions between different calls, and the variable is automatically trashed when the channel is hangup.
  • Make sure you do not put spaces around the equals sign in the assignment. Set(numTries = 4),with a space on either side of the "=", will set numtries to "". ...

Viewing all articles
Browse latest Browse all 5767

Trending Articles