Asterisk extensions.conf programing question

I am trying to setup call forwarding on my Asterisk PBX. Unfortunately I have not found a pre-programed solution that works for me so I decided to create my own solution.

Unfortunatly my solution revolves around an if statement, and I cant seem to get them working in Asterisk.

Can anyone tell me what language to base my code off of, or look at my current code and tell me where I went wrong.

Here is my code:

exten = s,1,Set(ZERO=0)
exten = s,2,SayDigits(${ZERO})
if (${DB(CFWD/${CID})} != ${ZERO}) {
exten = s,3,SayDigits(99)
} else {
exten = s,3,SayDigits(${DB(CFWD/${CID})})
}
exten = s,4,SayDigits(00)
exten = s,5,SayDigits(${DB(CFWD/${CID})})

It sets the Variable ZERO to 0, and then I check to make sure that the variable ZERO is set.

After that if does an if statement to check to see if the DB variable CFWD/CID where CID is equal to what extension I am calling from. That variable is set before, and it works just fine, as tested with my SayDigits command.

Now no matter what I do (I have tried =, ==, !=, >, < ect) it will always play the first section exten = s,3,SayDigits(99);, but never the second one.

Does anyone have any ideas?

You’ll have to use the GotoIf() statement. Then jump to a new spot in the extensions.conf file if a condition is true or not.

Here’s a piece of one of mine:

exten => s,11,GotoIf($[${correct} = 1]?savedigits,s,1:acquiredigits,s,1)

In this case, I’m checking to see if a person has pressed 1, because some digits entered are considered by the caller to have been correctly received. If they are, I proceed to a context called “savedigits” at priority s,1. If not, I go back to the context where I acquire the digits from the caller (“acquiredigits”) at priority s,1. (To give them another chance to enter digits.)

You can also leave off the second destination, and just have it as:

exten => s,11,GotoIf($[${correct} = 1]?savedigits,s,1)

If the condition is true, you’ll jump to the new line. If not, the priority just below the GotoIf() statement is the next one executed.

PERFECT!

This works beautifully. Thank you very much.

BTW, before you dig too far into doing forwarding on asterisk, have you tried *72 on your phone for forwarding and *73 to clear it?

On the asterisk system? Doesnt work.

On my actual phone line, yes. But I am setting this up for an office, and their are several people in the office who may need to forward their calls to an external extension.

Are you using voip phones? The ones I use all support *72 forwarding, and you can forward to anywhere you can dial as one string.

We have not yet recieved our sip phones yet, but they may support that I am not sure.

One of the main benefits of the Call Forward feature that I am working on (I am not finished yet, but almost) is that it supports Flash call forwarding, so it does not take up one of our phone lines to dial an external number.