login | register
Thu 21 of Aug, 2008 [06:00 UTC]

voip-info.org

Discuss [6] History

Asterisk Dialplan Globals

Created by: JazEzork,Last modification on Tue 24 of Jul, 2007 [18:29 UTC] by michael.davis

Dialplan Global Variables

Dialplan global variables and their initial values are defined in the extensions.conf file following the Dialplan General Settings. The global variables section begins with the header:

   [globals]

Following this header you may define global variables and their initial values.

Actually, Asterisk global variables are usually used not as variables but as constants. They are usually used to have a single place in your dialplan where you can specify values that you might want to change in the future if you change your PBX configuration.

The current value of a global variable can be changed in a dialplan using the SetGlobalVar command. The current value of a global variable can be referenced within the dialplan using the syntax:

   ${VariableName}

Note that global variable names are not case sensitive. ${MYGLOBAL} and ${myGLObal} are equivalent.

Example

Here is an example which defines some global variables used in the dialplan of a home PBX.

   [globals]

   ; Which extensions shall we ring when an incoming call comes in?
   INCOMING => Zap/3&Zap/4

   ; How long shall we ring those extensions before going to voicemail instead?
   RINGTIME => 3

   ; What sound file will we play as a voicemail announcement?
   VMANNOUNCE => mysounds/my-vm-announce

   ; Define the channels our extensions are connected on
   KITCHEN => Zap/3
   STUDY => Zap/4
   HALL => Zap/5

   ; When we want to make an outgoing call, what line(s) can we use?
   OUTGOING => Zap/1&Zap/2

Making these definitions does not, by itself, do anything. Asterisk does not intrinsically know what to do with a variable named "INCOMING", for example. It's up to you to define the variables you want and to make use of them the way you want in your dialplan.

In this example, the global variables have all been written with names in UPPERCASE. Global variable names are not case sensitive. Using uppercase for global variable names is just a convention to easily distinguish global variables from channel variables, which are often written in MixedCase.

For more information about using both global variables and channel variables in extensions.conf, see


See Also



Asterisk | Configuration | The Dialplan - extensions.conf

Comments

Comments Filter
222

333globals from another file

by cmaj, Wednesday 30 of April, 2008 [18:05:42 UTC]
To include global variables from another file, remove any globals heading from that file. Then in the globals section of extensions.conf, add #include my-other-file-with-just-globals.conf
222

333Problem solved

by seestheday, Monday 04 of September, 2006 [22:14:25 UTC]
In version 1.2.10 it is possible to access global variables using the AGI. My problem was unrelated to this. Thanks for everyones help.
222

333Re: How to reference global variables from AGI?

by seestheday, Saturday 29 of July, 2006 [20:03:59 UTC]
I haven't tried that $__GLOBAL_foo thing yet, but it's an interesting idea. I think those underscores are more for setting variables that are inherited by the following contexts, as opposed to actual global variables that are really constants and defined at in the |globals| section of the dialplan. They are really two different things.

I have asked this question on the asterisk-users mailing list and it appears to be a bug. I submitted a ticket and a developer there quickly provided a patch. The bug and patch are here: http://bugs.digium.com/view.php?id=7609

- Simon
222

333Re: How to reference global variables from AGI?

by chandave, Friday 28 of July, 2006 [05:33:53 UTC]
I haven't tested it myself, but have you tried to access the Global variable with 2 underlines charaters prefixed to the variable name? I.E. $GLOBAL_foo as $__GLOBAL_foo.

See ya...

d.c.
222

333How to reference global variables from AGI?

by seestheday, Thursday 27 of July, 2006 [23:46:21 UTC]
Does anyone know how to handle referencing global variables from the AGI? Is this possible?
222

333How about include?

by kniveton, Friday 09 of July, 2004 [22:43:16 UTC]
What if I want to include another context in the global context?

For Instance, based on a global, I want to include one set of global vars, or another.

include => foo
just sets the variable $

Please enter a valid 'page_name', 'page_id' or 'content_id' to include in this page.

to "foo".