IF, ELSEIF and ELSE condition in dialplan

I know and I’ve read about IF/ELSE in dialplan with GotoIf but what about if, elseif, else? Is there a way to have this kind of condition? For example I want to check the length of the incoming extension, like:

if(extenLength == 13)
    // goto this context
elseif(extenLength == 14)
   // goto another context
elseif(extenLength == 15)
   // goto third context
   // goto fourth context

use sequentials GotoIf()

Do you mean something like this?

exten => s,1,Set(foo=${LEN(${CALLER(num)})})
exten => s,2,GotoIf($["${foo}" = "13"]?context1:contextLength13)


exten => s,1,Set(foo=${LEN(${CALLER(num)})})
exten => s,2,GotoIf($["${foo}" = "14"]?context2:contextLength14)


exten => s,1,Set(foo=${LEN(${CALLER(num)})})
exten => s,2,GotoIf($["${foo}" = "15"]?context3:contextLength15)


For sequential GotoIf() I mean all on the same context, for example


Sorry, I’m not sure I understand it. In the example


What is “a”? And is {confirm} the callerid(num)?

Sorry I just tried to ilustrate my point, but I assumed you know how to use GotoIf()

${confirm}== is the variable to evaluate in this case you can substitute it for your own variable ${LEN(${CALLER(num)})}.

1== is the value for this particular case
a== is the destination, in this case a label on the current context you can also specify a different context

Thank you very much. Is a bit clearer now. Will try it a bit later and will write here to let you know if anything goes wrong or if is working.

It is working that way. Thanks!

Are you using AEL? That is more structured, but few people use it.

Hm, no, I don’t use it. I just googled it and seems really a bit better. I might try to switch to it once I get this ready.

Assuming your data is always going to be valid you can fake a switch statement with code like:

exten => s,1,Goto(LEN${extenLength})
 same => n(LEN13),Goto(context1,s,1)
 same => n(LEN14),Goto(context2,s,1)
 same => n(LEN15),Goto(context3,s,1)