Asterisk global variable help

Hi All,

I have asterisk 1.6 and trying to get a called extension from a macro.

Basically my end goal is to make a agi script to get the extension called for example 315 and add 1 infront of it. As we are moving to 4 digits extension.

Following is the macro which has the Extension in it ${EXTENSION}

[macro-stdexten]
exten => s,n(forward),Set(EXTENSION=${ARG1})

Verbose shows this
– Executing [s@macro-stdexten] Set(“IAX2/XXXX”, “EXTENSION=426”) in new stack

I then added this line below in the macro and I can see 426.
exten => s,n,Noop(${EXTENSION})
– Executing [s@macro-stdexten:19] NoOp(“IAX2/XXXX”, “426”) in new stack

But when I do Noop from outside the macro it returns empty.

I tried creating a global variable under that line with g option but that didn’t work. But i am not sure if i have the right cmd for it.

Can anyone help me.

Ok guys I have figure it out…

exten => s,n,Set(__JIX=${EXTENSION})

This shows up outside of macro

– Executing [s@TTest:2] NoOp(“Local/s@XXXX”, “426”) in new stack

I just need last help … how do I add 1 in front of ${JIX}

I basically want 1426 as right now $JIX is 426.

I tried
exten => s,2,Noop(1${JIX}) but that still shows 426.

exten => 9502,1,NoOP()
 same =>      n,Set(MYNUM=100)
 same =>      n,NoOP(MYNUM is ${MYNUM})
 same =>      n,Set(MYNUM=1${MYNUM})
 same =>      n,NoOP(MYNUM is ${MYNUM})
 same =>      n,Hangup()


  -- Executing [9502@kiniston-intern:1] NoOp("PJSIP/7001kiniston-00000050", "") in new stack
    -- Executing [9502@kiniston-intern:2] Set("PJSIP/7001kiniston-00000050", "MYNUM=100") in new stack
    -- Executing [9502@kiniston-intern:3] NoOp("PJSIP/7001kiniston-00000050", "MYNUM is 100") in new stack
    -- Executing [9502@kiniston-intern:4] Set("PJSIP/7001kiniston-00000050", "MYNUM=1100") in new stack
    -- Executing [9502@kiniston-intern:5] NoOp("PJSIP/7001kiniston-00000050", "MYNUM is 1100") in new stack
    -- Executing [9502@kiniston-intern:6] Hangup("PJSIP/7001kiniston-00000050", "") in new stack

Thanks John,

I have managed to wrap it up. I am pasting the solution so it might help someone out there. I am not expert so this is probably not as good as it gets and probably can be done better and shorter way.

In Macro I added new global variable

[Macro]
exten => s,n(forward),Set(EXTENSION=${ARG1})
#Added my global variable ${JIX}
exten => s,n,Set(__JIX=${EXTENSION})

#My menu basically forwards the calls to Skype For Business server and adds 1 in front of extension dialed.

[ToSkype]
include => external
exten => s,1,Macro(loopdetect); #hiddenincp#
exten => s,n,Set(XJ=1${JIX})
exten => s,n,Noop(${XJ})
exten => s,n,Dial(Local/416XXXXXX@internal,M(Skype^1^${XJ}))

[macro-Skype]
exten => s,1,Wait(${ARG1})
exten => s,n,SendDTMF(${ARG2})

You may not need a Macro for this, You can send DTMF directly from your Dial string with the ‘D’ option to Dial.

https://wiki.asterisk.org/wiki/display/AST/Application_Dial

Hi John,

I just tried that but I believe DMTF is being sent very early and Skype For Business is only picking last 3 digits.

I looked up to wait 1 second before sending the DMTF but I am not sure if its the right syntax.

Below is the new dial line i made. I am hoping that one after internal is the seconds to wait before sending DMTF. Do you know if that correct?

exten => s,n,Dial(Local/416XXXXXXX@internal,1,D(${XJ}))

Verbose confirms that 4 digits are being passed to DMTF

-- Executing [s@TTest:2] Set("Local/s@TTest-f8a9;2", "XJ=1376") in new stack
-- Executing [s@TTest:3] NoOp("Local/s@TTest-f8a9;2", "1376") in new stack
-- Executing [s@TTest:4] Dial("Local/s@TTest-f8a9;2", "Local/416XXXXXXXX@internal,1,D(1376)") in new stack

You are making a call which must be answered within 1 second, and there is no delay before the DTMF. The delay is done with pseudo digits in the DTMF.

Cool thanks for pointing me to right direction. Learning new stuff day by day :slight_smile:

I used D option with w(0.5 sec delay) and it worked out fine for me. I also added a voice prompt “ExtChanged” to notify caller that 3 digits has been changed to 4 digits and that current ext is now 1+Dialed Ext which is $[XJ}.

Here is the script if someone else ever needs it in future.

exten => s,n,Playback(ExtChanged)
exten => s,n,SayDigits(${XJ})
exten => s,n,Dial(Local/416NumberHidden@internal,D(w${XJ}))

Just a quick note for anyone wanting more time before sending DTMF you can add multiple wwww in there so putting 4 would mean 2 sec delay before it sends out DTMF.