Transfer call to next extension if previous INUSE

Hello,
I am trying to transfer call to next extension if previous is using (INUSE) or call is in progress. I tried to use EXTENSION_STATE(extension[@context]) to find the status as follow:

[sales] exten => s,1,Dial(SIP/123) exten => s,n,GotoIf($["${EXTENSION_STATE(123)}"="INUSE"]?passed:failed) exten => s,n(passed),Dial(SIP/124) exten => s,n(failed),Hangup();if other

But wasn’t successful. How can I do that?

You are checking the extension state after dialing SIP/123.

You also probably want to use the DEVICE_STATE dialplan function and get the status of SIP/123 instead of the extension state, since that device is what you would be trying to call.

There is also a window of time between checking the state and dialing where something else could theoretically place a call or the device could send a call into Asterisk.

I’m not sure if this is still true, but you also needed to have call limits enabled for device state to work in earlier versions.

Also, it is probably better to attempt the call and then check DIALSTATUS and/or HANGUPCAUSE, than to bother with device state at all.

It is important to understand the difference between extensions and devices in Asterisk. There is a zero or more to zero or more relation between them.

Thanks for your replay. I am new in Asterisk… Can you help me write down the code? I also tried like this:

exten => s,1,Set(GROUP()=OUTBOUND_GROUP) exten => s,2,GotoIf($[ ${GROUP_COUNT()} > 1 ]?try1:try2) exten => s,3(try1),Dial(SIP/124) exten => s,4(try2),Dial(SIP/123)

The above code was working but what will be happened if I have more then 2 extensions? For example 10 extensions.

I would start by replacing the first two lines by Noops, and then just add extra Dial lines on the end.

Alternatively, this is a degenerate case of what they queue application does.

Thanks for your reply david55 :smile:. Will you please little more explain what I will do with NoOp() function?

Nothing. That’s what it does. You will get close to what you want without the first two lines, so you should start from there and then see if you really need anything more complex. At least it will help you to clarify the specification.