Can not use variable as extension after assignment in dialplan. Why?

My idea is to use a variable as a extension.
The dialplan is:

[globals]
USER_1=1111
SUBSCRIBER_NUMBER=2222

[outgoing_CALL-7777]

exten => _.,1,Verbose(SUBSCRIBER_NUMBER before value assignment is:${SUBSCRIBER_NUMBER})
same => n,Set(SUBSCRIBER_NUMBER=${SHELL(echo 3333)})
same => n,Verbose(SUBSCRIBER_NUMBER after value assignment is:${SUBSCRIBER_NUMBER}) 
exten => ${SUBSCRIBER_NUMBER},n,Dial(SIP/${EXTEN})
same => n,Hangup()

and the CLI output is:


  == Using SIP RTP CoS mark 5
       > 0xb670a020 -- Strict RTP learning after remote address set to: 192.168.1.132:8000
    -- Executing [3333@outgoing_CALL-7777:1] Verbose("SIP/7777-00000003", "SUBSCRIBER_NUMBER before value assignment is:2222") in new stack
SUBSCRIBER_NUMBER before value assignment is:2222
    -- Executing [3333@outgoing_CALL-7777:2] Set("SIP/7777-00000003", "SUBSCRIBER_NUMBER=3333
    -- ") in new stack
    -- Executing [3333@outgoing_CALL-7777:3] Verbose("SIP/7777-00000003", "SUBSCRIBER_NUMBER after value assignment is:3333
    -- ") in new stack
SUBSCRIBER_NUMBER sfter value assignment is:3333

    -- Auto fallthrough, channel 'SIP/7777-00000003' status is 'UNKNOWN'

As u can see command exten => ${SUBSCRIBER_NUMBER},n,Dial(SIP/${EXTEN}) isn’t recognized…because of command:

same => n,Set(SUBSCRIBER_NUMBER=${SHELL(echo 6666)})

in other words if I assignement it in dialplan. Verbose showing real value but it isnt recognize as extension typed as: ${SUBSCRIBER_NUMBER}

If I omitt the line:

same => n,Set(SUBSCRIBER_NUMBER=${SHELL(echo 3333)})

variable in as extension is recognised and the call is routed.
Why it do not working if I reassignement the global variable again?

I even try instead of line:

same => n,Set(SUBSCRIBER_NUMBER=${SHELL(echo 3333)})

to type:

same => n,Set(SUBSCRIBER_NUMBER=3333)

but the result is same…

Any idea?

i have never try it, but I dont think you can use variables values as the diaplan extension

It’s not clear what you are trying to accomplish, but that ‘shell/echo’ bit implies that you need a deeper understanding into the dialplan language.

Any chance replacing your ‘dial line’ with:

same = n, dial(SIP/${SUBSCRIBER_NUMBER})

is what you are looking for?

If not, please reply with an explanation of what you are trying to accomplish and maybe someone can suggest the proper approach.

I’ll also answer the question at hand too - because the dialplan extension for “exten” is evaluated at load time, not dynamically. It becomes exten => 2222,n,Dial(SIP/${EXTEN})

As others have said though - you need to explain what you are doing because you shouldn’t need to do what you’re trying to do.

Thx everyone for suggestion and ideas.

…because the dialplan extension for “exten” is evaluated at load time, not dynamically

This explaining why it do not want to assignement the extension with value what is one step before showed that it is correct with Verbose function…
Hmm the logic is next:
Im using asterisk with chan dongle plugin. There are some type of huawei modem and sim card that are able to show the Subscriber Number as a sim card number with command:

dongle show device state dongle0

........
Mode                    : WCDMA
Submode                 : WCDMA
Provider Name           : I TIM
Location area code      : F046
Cell ID                 : 1977
Subscriber Number       : +393722222222
SMS Service Center      : +393756626300
Use UCS-2 encoding      : Yes
USSD use 7 bit encoding : Yes

The whole logic is to use the AGI script before the call and grep for Subscriber Number, return as a value to dialplan and use it as extension.
The second case is when the command:

dongle show device state dongle0
...
Subscriber Number: Unknown
...

In this case I would return from AGI script the letter ‘s’ and use it as extension in dialplan.
Why all this?
Because the manual of chan_donle said:
Chan_dongle

Incoming calls
On incoming call, chan_dongle tries to find matching exten in defined context (see dongle.conf). There is 3 different exten to search, in the following order:

  • Subscriber Number stored in SIM.
  • Number defined in variable exten in dongle.conf
  • s exten

I wanted to make an universal dialplan to not to be related with sim card and modem.