Help With GotoIf Command

Home » Asterisk Users » Help With GotoIf Command
Asterisk Users 6 Comments

Hi All,

For some reason I can’t get this GotoIf statement to work. Even if the name and number are the same it jumps to line 3. I’ve tried with and without the quotes around each variable.

exten => s,1,GotoIf($[“${CALLERID(name)}” = “${CALLERID(num)}”]?:3)
exten => s,2,NoOp(they are the Same)
exten => s,3,NoOp(they are different)

The wisdom of this group is much appreciated.

This is an example only. I know the code will display both NoOp lines if the name and number is the same.

Regards David Klaverstyn

6 thoughts on - Help With GotoIf Command

  • David Klaverstyn wrote:

    exten => s,1,NoOP(${CALLERID(name)})
    exten => s,n,NoOP(${CALLERID(num)})

    Will probably give you some clues.

    Doug

  • By definition you are doing if not equal go to 3. Gotoif($[condition]?[true]:false). Look at your CLI output and you will see the evaluation of the condition as 1 or 0.

    From: asterisk-users-bounces@lists.digium.com
    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of David Klaverstyn Sent: Wednesday, September 05, 2012 4:31 AM
    To: Asterisk Users Mailing List – Non-Commercial Discussion
    (asterisk-users@lists.digium.com)
    Subject: [asterisk-users] Help with GotoIf Command

    Hi All,

    For some reason I can’t get this GotoIf statement to work. Even if the name and number are the same it jumps to line 3. I’ve tried with and without the quotes around each variable.

    exten => s,1,GotoIf($[“${CALLERID(name)}” = “${CALLERID(num)}”]?:3)

    exten => s,2,NoOp(they are the Same)

    exten => s,3,NoOp(they are different)

    The wisdom of this group is much appreciated.

    This is an example only. I know the code will display both NoOp lines if the name and number is the same.

    Regards David Klaverstyn

  • David,
     
    I believe there a error of sintax:
     
    Wrong:
     
    exten => s,1,GotoIf($[“${CALLERID(name)}” = “${CALLERID(num)}”]?:3)
     
    Correct:
     
    exten => s,1,GotoIf($[“${CALLERID(name)}” = “${CALLERID(num)}”]?3)
     
    Thanks,
     
    Rodrigo Bastos de Moura.

  • You need to verify if the {CALLERID(num)} can actually match what your
    {CALLERID(name)} looks like. More than likely, the (num) has some sort of brackets around it, such as <>, or perhaps it’s starting with a +. You can try to use the FILTER function on it, to strip away any additional characters that you don’t want to see or try to match on.

    exten => s,1,GotoIf($[“${CALLERID(name)}” =
    “${FILTER(0123456789,${CALLERID(num)}}”]?:3)

    That is, if you’re just looking for numeric callerid. If you also want to account for extra characters, you can add those to the first part of the filter.

  • Hi All,

    Thanks for all your suggestions. It turns out that the CID Name was sent with a space at the end of the number and that is why there was never a match.

    Regards David.

  • Hi,

    This is exactly why it is very important and wise to attach CLI verbose logs and other traces so the real issue gets resolved quicker than making all the people figure out the possibilities.

    BR
    Sammy