Queue Misc Destination?

We are using freePBX distro 13.0.191.11 essentially as a switch. All inbound comes into freePBX, and then is sent to a SIP dialer, SIP IVR or digital PBX via Dahdi. This done by routing the inbound DID to a misc_dest for the appropriate system.

The working misc_dest dial entry is 777${CALLERID(dnid)}

Now, if for instance the IVR is down for maintenance (or an oops) we want the calls to hold in queue in this freePBX switch until the target saystem comes back up. I have accomplished this by creating 1 queue per DID and creating a custom extension to put in Queue Agents.

Here’s the custom extension I can add to queue agent that works with 1 queue per DID: 7778136714021
the dial patterns takes off the 777 and send the call onto the correct outbound route. The DID of course is 8136714021, which is also configured in the target system.

However, that is not really a solution. With hundreds of DIDs that will be an admin nightmare.

I tried making dialplan entry in extensions_custom.conf like this:

[from-internal-custom]
exten => 777777,1,Dial(Local/777${CALLERID(dnid)})

I then entered 777777 in Queue Agents, but that resulted in the extension not being passed the DNID. From CLI:

-- Executing [[email protected]:1] Dial("Local/[email protected];2", "Local/777") in new stack
[2017-05-09 11:35:55] NOTICE[28922][C-00000020]: core_local.c:740 local_call: No such extension/context [email protected] while calling Local channel
        -- Couldn't call Local/777

So apparently with this scheme the DNID is not passed? I don’t know why that is. Any ideas?
Or does anyone know of a better way to accomplish this?