Dialplan issue - with numbering

I am trying to develop a new dialplan and having a problem with numbering…
I have a lot of if statements - example: if user hits 1 then go to 3 or if user hits 10 go to 40.
I realized that the dialplan statements have to be in numbering order 1,2,3,4,5
When I try to add a new function or feature - i have to constantly recheck insert new numbers and re-order the numbers accordingly because of the new statements that I inserted - so i have to go and recheck the if statements over again and redo the numbers there as well.

Is there a better way to do this ??? I mean with the if statements or the line numbering ??


Use n for the priorities two upwards.

For branch targets put an alphabetic label, in parentheses, after the n. use that label in the GoTos.

All the examples in extensions.conf.sample do it this way.

Also consider the possibility of using contexts

Or - as another alternative - try to implement Your dialplan in ael-Logic as this makes You independent from the numbering in a more “programming-language-like” manner. Check the samples in extensions.ael.sample.

thanks guys…i am barely a programmer…just would like to know what i am doing wrong in this…trying to convert this part of my dialplan to the n,(label) thing - can you tell me what i am doing wrong ???

I get the follwoing error:
– Executing [1@pcom-drv:21] MYSQL(“SIP/inphonex_peer-00000014”, “query resultid 1 select count(*) from w6h8a_community_fields_values WHERE (field_id =‘6’) and value =‘22222’”) in new stack
– Executing [1@pcom-drv:22] MYSQL(“SIP/inphonex_peer-00000014”, “fetch fetchid 2 check”) in new stack
– Executing [1@pcom-drv:23] MYSQL(“SIP/inphonex_peer-00000014”, “disconnect 1”) in new stack
– Executing [1@pcom-drv:24] GotoIf(“SIP/inphonex_peer-00000014”, “0?notinsystem:insystem”) in new stack
– Goto (pcom-drv,1,27)
[Sep 21 14:57:45] WARNING[7275]: pbx.c:4071 pbx_extension_helper: No application ‘’ for extension (pcom-drv, 1, 27)
== Spawn extension (pcom-drv, 1, 27) exited non-zero on ‘SIP/inphonex_peer-00000014’
== Spawn extension (to-inonex, 1221, 1) exited non-zero on ‘SIP/1001-00000012’

; ** Check if user with ${CALLERID} exist?
exten => 1,20,MYSQL(connect connid localhost usr password db)
exten => 1,21,MYSQL(query resultid ${connid} select count(*) from w6h8a_community_fields_values WHERE (field_id =‘6’) and value =’${phone_num}’)
exten => 1,22,MYSQL(fetch fetchid ${resultid} check)
exten => 1,23,MYSQL(disconnect ${connid})
exten => 1,n,GotoIf($[${check} = 0]?notinsystem:insystem)
exten => 1,n(notinsystem),read(notsys,/var/lib/asterisk/proj2/65-drv-numnotinsystem10,1,3,3)
exten => 1,n,GotoIf($[${notsys} = 1]?9:100)
; ** Get phone number from driver and Check Password

exten => 1,n(insystem),(${answer})
exten => 1,27,NoOp(${answer})
exten => 1,28,Set(i=1)
exten => 1,29,While($[${i} <= 3])
exten => 1,30,read(trypassword,/var/lib/asterisk/proj2/29-enterpassword,4,3,3)
exten => 1,31,MYSQL(connect connid localhost usr password db)
exten => 1,32,MYSQL(query resultid ${connid} select pin from w6h8a_community_verify_mobile where MobileNo=’${phone_num}’)
exten => 1,33,MYSQL(fetch fetchid ${resultid} password1)
exten => 1,34,MYSQL(Clear ${resultid})
exten => 1,35,Goto(pcom-drv,1,36)
; exten => 1,35,MYSQL(query resultid ${connid} SELECT MD5(’${trypassword}’))
; exten => 1,36,MYSQL(fetch fetchid ${resultid} password2)
; exten => 1,37,MYSQL(disconnect ${connid})

i have different contexts in my script - could it be that I need to use the context as well as the label ???
how would i do that ???

exten => 1,n(insystem),???(${answer}) ; this is priority 27 - there should be an application where I have put question marks.
exten => 1,27,NoOp(${answer}) ; You can’t have two priority 27s.

thanks for the reply.

  1. I understand now that there needs to be an app.
  2. There can be no two 1,27s ? I thought the idea of labels that we do not have to worry about numbering ? I will try with more priorities. But need to know - I can start with say 1,100 after the labeling lines ?? Can I skip priorites - meaning 27 and then go to 100 afterwards ???

If you use n, you should, normally, use it on every line except the first.

Gaps in the numbering will terminate the dialplan at that point, although you can jump around them.

You can also put labels on numbered steps.