login | register
Wed 09 of Jul, 2008 [05:41 UTC]

voip-info.org

Discuss [0] History

Asterisk cmd Set

Created by: trevmeister,Last modification on Sat 21 of Jun, 2008 [10:37 UTC] by JustRumours

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)


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 hungup.
  • 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


Comments