Search:

Asterisk cmd Set

Synopsis

Sets variable to value

Version differences: This command is not available in Asterisk 1.0.9. Use SetVar instead. As of v1.2 SetVar is deprecated and we are back to Set.

Description

   Set(variablename=value[|variable2=value2][|options])

This function can be used to set the value of channel variables or dialplan functions. It will accept up to 24 name/value pairs. 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.

Options

  • 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

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])


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 "".
  • If trying to zero out the CALLERID(name) do not use empty quotes, use Set(CALLERID(name)=)

Try using the variable in your dialplan:

 Playback(${variablename})
 SayDigits(${variablename})



See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: trevmeister,Last modification on Mon 01 of Dec, 2008 [10:35 UTC] by rootol


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 
Sponsored by:




Search: