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

Leif Madsen leif.madsen at asteriskdocs.org
Thu Jul 23 07:24:46 CDT 2009


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())})

Leif Madsen.
http://www.leifmadsen.com
http://www.oreilly.com/catalog/asterisk



More information about the asterisk-users mailing list