Asterisk 1.8 pass variable between contexts

hello team, pls tell to use variable between contexts in dialplan.

asterisk 1.8 pass variable between contexts

As I need to use same variable with value change in different context.
thanks

If you are still using Asterisk 1.8, you should really consider upgrading.

Contexts do not establish separate namespaces. A channel variable named ‘FOO’ is the same in [incoming-call] as it is in [lookup-did].

You can concatenate (prefix or suffix) a channel variable name with the context name if you want to create the illusion of context based namespaces.

thanks for replay.
Yes, I will upgrade soon my asterisk but it will take some time.
can you please give some example to go ahead.
at present i am not able to get value from different context in my dial plan.
thanks

It doesn’t work like that. You need to show us what you have tried, and we will try to explain why it it doesn’t work.

Hello David

Following is example/content of dialplan under Asterisk 1.8 , Here variable value from Classt1 is not transferring to next context lecture, pls see and guide to solve this. I have tried with few changes but still not resolved.

[Classt1]
exten => s,1,Set(NUM=0)
exten => s,n,Set(NUM2=0)
exten => s,n,Set(ANSVALUE=0)
exten => s,n,Set(keytone=0,g)
exten => s,n,Set(Classp1=classes/Class1/)
exten => s,n,Set(Classps1=“classes/Class1/books/hindi/”)
exten => s,n,Set(__Classpstt1)=105)

[Lecture]
;exten => s,n,Set(LANGUAGE={CHANNEL(language)}) exten => s,n,Set(LANGUAGE2={__Classpstt1})
exten => s,n,IMPORT(LANGUAGE3=${Classps1})

I assume missing linebreaks are the fault of the forum software…

When reading a variable, do NOT prefix with __

Hi ,
I said i done few r&d like with prefix __ or without also and else also which i got through searching. I am still waiting for solution with same version.
thanks

You have, to my knowledge, never been able to read a variable like ${__Variable}, which is what you do in your example. The _ and __ prefixes are only used when SETTING variables, to signal inheritance to forked channels. That is, if you set a variable with

Set(__Variable)=Something

You read it with

${Variable}

I done already but it is not working.

I tried with Asterisk 17.x but problem remain same. pls see
variable value from one context to other context is not transferring

[class1]
exten => s,n,Set(Classp1=classes/Class1/)
exten => s,n,Set(Classps1=classes/Class1/books/hindi/)
exten => s,n,Set(__FOO=109)
exten => s,n,Set(Classpstt1=105)

[Lecture]
exten => s,n,Set(LANG2={Classpstt1}) exten => s,n,Set(FOO2={FOO})
exten => s,n,set(LANGUAGE3={Classps1}) exten => s,n,set(LANGUA3={Classpst1})
exten => s,n,set(LANGUA4=${Clat1})
exten => s,n,Set(level2=quiz)

Log

uiz:9] Set(“SIP/demo-alice-0000000b”, “LANG2=”) in new stack
– Executing [s@LectureQuiz:10] Set(“SIP/demo-alice-0000000b”, “FOO2=”) in new stack
– Executing [s@LectureQuiz:11] Set(“SIP/demo-alice-0000000b”, “LANGUAGE3=”) in n

Are they the same call or different calls?

it is from same call, I just want to transfer variable value from one context to second context

[class1]
exten => s,n,Set(Classp1=classes/Class1/)
exten => s,n,Set(Classps1=classes/Class1/books/hindi/)
exten => s,n,Set(__FOO=109)
exten => s,n,Set(Classpstt1=105)

[Lecture]
exten => s,n,Set(LANG2={Classpstt1})
exten => s,n,Set(FOO2={FOO})
exten => s,n,set(LANGUAGE3={Classps1})
exten => s,n,set(LANGUA3={Classpst1})
exten => s,n,set(LANGUA4=${Clat1})
exten => s,n,Set(level2=quiz)

Log

uiz:9] Set(“SIP/demo-alice-0000000b”, “LANG2=”) in new stack
– Executing [s@LectureQuiz:10] Set(“SIP/demo-alice-0000000b”, “FOO2=”) in new stack
– Executing [s@LectureQuiz:11] Set(“SIP/demo-alice-0000000b”, “LANGUAGE3=”) in n

That’s not the full log, and the context you’re showing is “LectureQuiz” not “Lecture” as is provided in your configuration.

There is also nothing in the provided configuration that moves between contexts (such as Goto).

this is full log of Asterisk 17.
yes i deleted word quiz from context name.

It’s not a full call log of what is going on. You’ve copy/pasted 3 lines of it, and I expect the provided configuration is incomplete. Without seeing everything that is going on the people here can only guess.

Hi ,
can you help me with suggestion/example , how to transfer variable value from one context to other context.

[incoming]
exten => s,1,Set(TEST=Hello)
exten => s,n,Goto(next,s,1)

[next]
exten => s,1,NoOp(Test is ${TEST})

still value not coming with your example

– Executing [s@LectureQuiz:16] NoOp(“SIP/demo-alice-00000012”, "Test is ") in new stack

You’ve placed the example in your existing dialplan. As I stated previously you need to show the COMPLETE configuration and the COMPLETE log. You can’t just pick out the relevant parts.