Name

GotoIf() — Conditionally goes to the specified priority

Synopsis

GotoIf(condition?label1:label2)

Sends the call to label1 if condition is true or to label2 if condition is false. Either label1 or label2 may be omitted (in that case, we just don’t take the particular branch), but not both.

A label can be any one of the following:

  • A priority, such as 10

  • An extension and a priority, such as 123,10

  • A context, extension, and priority, such as incoming,123,10

  • A named priority within the same extension, such as passed

Each type of label is explained in this example:

[globals]
; set TEST to something else besides 101 to see what GotoIf()
; does when the condition is false
TEST=101
;
[incoming]
; set a variable
; go to priority 10 if ${TEST} is 101, otherwise go to priority 20
exten => 123,1,GotoIf($[ ${TEST} = 101 ]?10:20)
exten => 123,10,Playback(the-monkeys-twice)
exten => 123,20,Playback(tt-somethingwrong)
;
; same thing as above, but this time we'll specify an extension
; and a priority for each label
exten => 124,1,GotoIf($[ ${TEST} = 101 ]?123,10:123,20)
;
; same thing as above, but these labels have a context, extension, and
; priority
exten => 125,1,GotoIf($[ ${TEST} = 101 ]?incoming,123,10:incoming,123,20)
;
; same thing as above, but this time we'll go to named priorities
exten => 126,1,GotoIf($[ ${TEST} = 101 ]?passed:failed)
exten => 126,15(passed),Playback(the-monkeys-twice)
exten => 126,25(failed),Playback(the-monkeys-twice)

See Also

Goto(), GotoIfTime(), GosubIf(), MacroIf()