[asterisk-users] ExecIf and empty variables (early evaluation)

Tilghman Lesher tilghman at mail.jeffandtilghman.com
Thu Jul 23 13:00:07 CDT 2009


On Thursday 23 July 2009 07:24:46 Leif Madsen wrote:
> Benny Amorsen wrote:
> > Imagine that you have this code:
> >
> > exten => _X!,n,Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}))
> >
> > If ${QueueName} happens to be unset, this will cause a warning:
> >
> > [Jul 22 14:26:17] ERROR[8114]: app_queue.c:5187
> > queue_function_queuewaitingcount: QUEUE_WAITING_COUNT requires an
> > argument: queuename
> >
> > The obvious solution:
> >
> > exten => _X!,n,ExecIf($["${QueueName}" !=
> > ""]?Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}))
> >
> > However, this doesn't actually work! Functions and variables on the
> > right hand side are evaluated BEFORE it is decided whether it needs to
> > be executed at all!
>
> Try this, as I think the IF() function works differently (I could be wrong
> though):
>
> exten => _X!,n,Exec(${IF($["${QueueName}" !=
> ""]?Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}:NoOp())})

You're incorrect.  The same problem follows this one.  Separating the
evaluation out into multiple steps is the only way I know to make this work
as expected:

exten => _X!,n,GosubIf(${LEN(${QueueName})}?waitingcount(foo,${QueueName}))
...
exten => _X!,1000
(waitingcount),Set(${${ARG1}}=${QUEUE_WAITING_COUNT(${ARG2})})
exten => _X!,n,Return

-- 
Tilghman & Teryl
with Peter, Cottontail, Midnight, Thumper, & Johnny (bunnies)
and Harry, BB, & George (dogs)



More information about the asterisk-users mailing list