GotoIf in Asterisk 1.4.4 doesn't work

I must be missing something:

Dial plan:


exten => h,2,Set( COUNT = ${VMCOUNT( ${VMBOX} )} )
exten => h,3,GotoIf( $[ ${COUNT} = 0 ] ? 10 : 20 )

Result:

Executing [h@default:2] Set(“Zap/6-1”, “COUNT=2”) in new stack
Executing [h@default:3] GotoIf(“Zap/6-1”, " 0 ? 10 : 20") in new stack
Goto (default,h,10)

Executing [h@default:2] Set(“Zap/5-1”, “COUNT=0”) in new stack
Executing [h@default:3] GotoIf(“Zap/5-1”, " 1 ? 10 : 20") in new stack
Goto (default,h,10)

I can’t figure it out, I set COUNT to be the voicemail count and you can
see it set to 2 and 0 in both of the above calls, but Goto(10) is always
called. I’ve tried wrapping things in quotes in case there is a typing
issue but that doesn’t change anything. I’m about to report it as a bug
but thought I would run it passed the forum first in case I’m missing
something obvious.

Also, does anyone else notice that asterisk 1.4.4 likes to segfault?

schu

Hi,

I think the problem is in spaces. Remove all spaces inside the GotoIf statement, like

exten => 4,3,GotoIf($[${COUNT}=2]?4:5)

I think it does not accept spaces. With spaces it always goes to the first choice which is extension 10 in your case.

Try it and let us know if it worked.

Thanks for the suggestion, however that didn’t seem to make any difference. White space doesn’t change the outcome where the expression is always evaluated true.

Other thoughts?
schu

I suspect this has to do with the fact that you are in the hangup part of your dialplan.
If COUNT is a local variable, it is emptied when the channel hangs up.

The only remedy I know is using a global variable in hangup parts of dialplan, but perhaps there are beter ways…

Thanks for the suggestion, however COUNT is set in the h extension:

exten => h,2,Set( COUNT = ${VMCOUNT( ${VMBOX} )} )

You can also see it set correctly in the debug output.

I have created a bug report showing this problem so hopefully a developer will fix it as it’s pretty basic stuff. Until then I now pass the count to my MWI script because expressions do work in perl.

schu

After taking all spaces out of everything it does work. I’m not sure what I did wrong last time I tried that, but it is working now.

Thanks,
schu

Even when a variable is set in the hangup extension, it remains a fact that the use of local variables in a non-existing channel environment is an “undocumented feature”, AFAIK.
So it remains dangerous using it this way, IMHO you cannot be sure later versions of Asterisk will comply to current behaviour.

Could you give me GotoIf examples of incoming call, I make it like this for recording File Name purpose : 20070530-123059-Agent007

exten => s,1,Answer
exten => s,2,GotoIf($[${CALLERID(num)}=Agent/007]?6:9
exten => s,2,GotoIf($[${CALLERID(num)}=Agent/008]?8:9

exten => s,6,Set(MONITOR_FILENAME=/usr/local/src/${TIMESTAMP}-Agent007)
exten => s,7,Goto(9)
exten => s,8,Set(MONITOR_FILENAME=/usr/local/src/${TIMESTAMP}-Agent008)
exten => s,9,Queue(queue0)
exten => s,10,Hangup

How could we program it, so the Recording File become this:
20070530-123059-Agent007

The above code is not working