[SOLVED] Variable defined with setVar via AMI is caching in the dialplan

I create a variable to treat a dialplan event via AMI and getting a strange issue because the same contexts are used for AMI calls and directly, but when I use via AMI a variable is defined and without AMI this variable didn’t exist the name of it is newCallerId the problem is that this variable is caching the last value and is getting a wrong path with a call make directly.

The question is: Asterisk save the value of the variable with different calls? Any tip how I can solve it?

Looks like the setVar from AMI define a global… anyone can confirm that?

It depends on the arguments you have used. If no channel is provided, then it would set a global variable.

jcolp, well then was it the issue… How can I refer the actual channel?

Thanks for the answer.

The Channel name is provided using the “Channel” argument[1].

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+ManagerAction_Setvar

Thanks very much jcolp, I solved the issue only defining the channel.


Hello, updating again, didn’t solved because the variable continue with the last value defined for the same channel and didn’t resolve my problem.

Have another option how to solve that, defining a non global variable?

It’s not clear what you mean. You’ll need to give a specific example of how it is behaving and how you need it to behave.

Well. Basically I have this line in my PHP AGI script, this script uses libraries from PAMI on github project:

new SetVarAction(‘newCallerId’,’’.$strCallerId.’’,’’.$canalDest.’’)

This line define a variable called newCallerId that is used in my dialplan to validate and define a new callerId (only if is was defined), the issue is that sometimes this value should be empty and I noticed that is always with some value because it holds the last variable value.

I use a general context called [macro-user-callerid] that has this line:

exten => s,n(continue),ExecIf([{newCallerId}!=""]?Set(CALLERID(number)={newCallerId}):Set(CALLERID(number)={CALLERID(number):0:40}))

And it is always getting the true path because the variable value is never removed.

We are using Asterisk 11.

I’m pretty sure your problem is because you don’t understand how things are supposed to work, but you haven’t provided enough detail to be able to work out exactly what you false assumption is.

Well, let me try to provide more information about my whole scenario.

Basically, I use AMI in 2 points and different situations:
1 - Use to start the first call that will call for one extension as an example we can suppose 1004 extension; When it attend the call automatically start a call for an external number XXXXXXXXX; When it attended a execute a second PHP script for transfer the call for another channel/extension, as example exten 1005; This is the script that is having problems.

2- The script for transfer use PAMI project and implements 2 methods: SetVarAction and RedirectAction transfer it’s working well, the issue is SetVarAction that is caching the last value defined, looing that defined it globally and then how I reuse the same context it’s causing trouble.

Can you understand the scenario? Is it a better description?

More information about the PAMI project can consult here:

The solution was to create a new context to change the variable value:

exten => _X.,1,Set(newCallerId2={newCallerId}) same => n,Goto(from-internal,{EXTEN},1)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.