Go To IVR If Queue Wait Count Greater Than Zero

I was trying to set up a dynamic route using a guide I believe from @lgaetz (I wish I saved the link, but he referenced it recently). Essentially here is what I am trying to accomplish:

Caller (whether from the public or internal) calls our helpdesk queue number:
–if they are the only caller (all agent(s) available to take call), send call straight to the queue and be done
–if there is at least one other caller (looking at the ${QUEUE_WAITING_COUNT} variable):
----send call to an IVR that says "all agents are busy, press 1 to continue holding, or 2 to leave a voicemail

I do have an inbound route set for the helpdesk queue number to go to the dynamic route:

I also have it go to the dynamic route if calling from the inside:

exten => 5555,1,GoSub(dynroute-2,1,1)
same => n,Hangup()

It works as expected for the first caller - if I make a test call and the queue is empty. Then I add another call in, so the wait count will be 1, that’s fine. When I add a third call in however, it doesn’t go to the IVR. It just goes to the queue announcement saying they are second in line, then plays music on hold.

I confirmed the variable after I put the second call in is greater than 0 (I call 222 to get that value)

– Executing [[email protected]:1] NoOp(“PJSIP/3717-00000054”, “Count=1”) in new stack
– Executing [[email protected]:2] Hangup(“PJSIP/3717-00000054”, “”) in new stack

I am not sure if I set the dynamic route up incorrectly or not. Here’s what I have:

How I understand it, that value will be either 0 for false (0 calls waiting), or 1 for one or more waiting. Then I’m using that on the match - 0 waiting will just send straight to the queue, while 1 or more waiting will go to the IVR.

Here is a pastebin of the 3rd call. I can see it in there hitting the dynamic route (dynroute-2), but it seems to drop off there?


I’d try disabling substitution, as, assuming this is the correct source code for the distributed module, I think this will greatly mangle your square bracketed expression:

and probably explains why the computed expression is evaluating to just $

As it says in Dynamic Routes User Guide - PBX GUI - Documentation

:warning: IMPORTANT - when defining lookup queries or destinations that contain square brackets and it is not the intent to reference a Dynamic Route Variable then you must set Enable Substitutions to No.

1 Like

Ah, makes sense! I set the substitutions to “No” and tested around. Everything seems to be working as expected now.


1 Like

I guess a follow up to this:

So, if the first person is in a call with the only agent on the queue, the wait count is 0 of course. When a second phone calls into the queue, I’d like it to hit the IVR, not go directly into the queue. But because that count is 0 before they call, the ${QUEUE_WAITING_COUNT} > 0 resolves to false, so they get sent straight into the queue.

Is there another variable I can check, or another method, to make it so the calls are sent to the IVR beginning with that second person that calls in? The third person who calls in, it works fine because at that point the wait count is > 0.

Sounds like you’re doing a lot of work to make a queue behave like a ring group. In a ring group with skip busy enabled, if everyone is busy call will go immediately to failover destination. Are there other queue features that you need that force you to use it?

I guess looking between the two, a ring group could be the route to go. I haven’t worked much with them - does it allow extensions to log in and out of the group at will, or is there a workaround to do that? In our whole system we only have need for one queue, our IT helpdesk, and that typically has anywhere between 2 - 4 agents logged in at any given time. No need for static agents, they would all be dynamic.

Also looking at the ring group settings more, there doesn’t seem to be a way to set a wrapup time like for queues (generally we have a three minute wrapup time, any shorter and the agents get a little annoyed!)

If you’re logging members in/out then you need to stick with queues, doing that with a ring group is not supported.

Instead of checking the value of QUEUE_WAITING_COUNT, you’re going to need to experiment with a value returned by QUEUE_MEMBER:

uc-68246819*CLI> core show function QUEUE_MEMBER

  -= Info about function 'QUEUE_MEMBER' =-

Provides a count of queue members based on the provided criteria, or updates a
queue member's settings.

Allows access to queue counts [R] and member information [R/W].
<queuename> is required for all read operations.
<interface> is required for all member operations.


    logged - Returns the number of logged-in members for the specified queue.
    free - Returns the number of logged-in members for the specified queue that
    either can take calls or are currently wrapping up after a previous call.
    ready - Returns the number of logged-in members for the specified queue
    that are immediately available to answer a call.
    count - Returns the total number of members for the specified queue.
    penalty - Gets or sets queue member penalty.  If <queuename> is not
    specified when setting the penalty then the penalty is set in all queues
    the interface is a member.
    paused - Gets or sets queue member paused status.  If <queuename> is not
    specified when setting the paused status then the paused status is set in
    all queues the interface is a member.
    ringinuse - Gets or sets queue member ringinuse.  If <queuename> is not
    specified when setting ringinuse then ringinuse is set in all queues the
    interface is a member.

looks like maybe something like



1 Like

Perfect! I got this working now I believe. Tested from a few phones and it sends me to the IVR if I call now and the agent is already tied up.


Thanks very much, @lgaetz, for your help! I’ve been at FreePBX now for about nine months (for work - for home, I set one up during last summer), but still feel like a newbie sometimes.

1 Like

I’m told that feeling goes away around the 15 year mark.

Feel free to summarize it all with some screen caps etc and post to the tips and tricks category.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.