Stuck with checking is variable set

Hi guys,

I am stucked with variables. In my dial plan when incomning call come,
if incoming did matches extension I just cut last three numbers from
did an call that extension, something like this:

exten => _079586XXX,1,Dial(SIP/${EXTEN:6})
same => n,Hangup()

but sometimes did doesnt match ext. and then I setup global variable
something like this:


and then with that variable I can call extension 108. So I want to make
something like GotoIf, where if variable with “DIDsomenumber” exist go to that part
of dial plan if not just Dial(SIP/${EXTEN:6})
So I am stucked with ways to discover in dial plan is variable set or not,
if I let say in macro put somethin like this, where MACRO_EXTEN is icnoming

same => n,NoOp(************ ${DID${MACRO_EXTEN}} *************)
same => n,GotoIf($[${EXISTS(${DID{MACRO_EXTEN}})}]?yes:no)

asterisk always see that variable doesnt exist, NoOp detect correctly
value of variable which is in this case 102 and function EXIST doesnt:

NoOp(“SIP/sometrunk-00000027”, “************ 102 *************”) in new stack
– Executing [s@macro-searchExt:4] GotoIf(“SIP/sometrunk-00000029”, “0?yes:no”) in new stack

I also try with LEN without success. Is there any better way to solve this?

I hadn’t realised you could dynamically generate variable names. Maybe that doesn’t always work. You could try assigning it to a simple variable and then testing that.

Also you you could try $["…" = “”]


Seting and unsetting varibles seems to be getting complicated.

how we have done this in the past is use the astdb
so we have DID 123 321 in the astdb

can come in 01234456123
we match on the back 3 digits by looking them up in the db
this matches to 123 so we dial exten 321
this also made the DID dynamic as well

find solution,
acctually LEN is answer:

same => n,GotoIf($[${LEN(${DID${MACRO_EXTEN}})}>2]?yes:no)

and thats it, I preffer rather this way then setting DID through asteriskdb because off bacckup.