Dialplan Question: Variables In GoTo() ?

Home » Asterisk Users » Dialplan Question: Variables In GoTo() ?
Asterisk Users 2 Comments

I can’t seem to find a definitive answer on this, and I really don’t want to risk breaking a production server to find out; so I am going to try asking this here, and maybe anyone else in the same situation searching the archives sometime in future will find the answer I get.

Can you use variables in the target of a GoTo() statement?

What I am specifically thinking of is this;

[from_some_source]
exten => s,1,AGI(look_up_stuff.agi,${CALLERID(num)},${EXTEN})
; this AGI script sets variables: next_context, next_ext, next_step exten => s,n,GoTo(${next_context},${next_ext},${next_step})

Will this work? Does Asterisk evaluate expressions like this, or does it expect literals?

2 thoughts on - Dialplan Question: Variables In GoTo() ?

  • Yes. Here are a few examples from one of my dialplans:

    ; invalid template
    [i](!)
    exten = i,1, verbose(1,[${EXTEN}@${CONTEXT}])
    exten = i,n, goto(${CONTEXT},s,1)

    ; look up (set) DNIS (DID) channel variables
    exten = _x.,n, goto(lookup-dnis,${EXTEN},1)

    ; dispatch to selected application
    exten = _[123456],n, goto(${PRODUCT-${EXTEN}-APPLICATION},s,1)

    This particular dialplan uses the invalid template in around 30 contexts and ‘goto(${CONTEXT},s,1)’ about 15 times. Note that the last example
    ‘nests’ the variable expansion — a variable within a variable.