How do I forward secondary dialled digits (from an IVR) as a CID to a trunk?

I am running Free PBX and Asterisk from a distro install on a server.

My question is “how do I forward secondary dialled digits (from an IVR) as a CID to a trunk?”

I have an inbound route that puts the calls through to an IVR. The IVR allows users to dial extensions and it also allows them to dial a 7 digit number beginning in 0 to get to a trunk using the dial patern _0xxxxxx

This works without any problems. However I would like the newly dialled 7 digit number to be passed to the trunk as the CID. Currently the From CID is the phone number that dialled the inbound route (i.e my mobile number)@ the server IP address and the To CID is the DID of the inbound route @ the server IP address.

I have tried using the Set CallerID modual along with the asterisk EXTEN variable to change the CID number on the trunk.

However I get a strange result, the EXTEN variable seems to be set to 3 regardless of the number I dial to reach the trunk. The From CID is [email protected] IP address.

Has anyone done this before or does any one know how to do this?

Any help would be greatly appreciated.

P.S how do I insert or attach images

Using FreePBX 2.11 I can confirm what you are seeing, you can’t use the ${EXTEN} variable in the Set CallerID module. For some reason ${EXTEN} gets overwritten by a single digit which (I think) represents which Set Caller ID destination you are using. Not sure if this is a bug, but encourage you to file a ticket reporting it.

To do what you want will probably require some custom dialplan under the [from-internal-custom] section of /etc/asterisk/extensions_custom.conf. You will want to break up the ${EXTEN} variable with colons (eg. ${foo:offset:length})

so if your user dials for example a nine digit dial number then an * then a nine digit CID number the dialplan to break that up would be something like this:

[from-internal-custom] exten=>_xxxxxxxxx*xxxxxxxxx,1,set(${CALLERID(num)}=${EXTEN:10}) exten=>_xxxxxxxxx*xxxxxxxxx,n,noop(setting caller id to ${EXTEN:10}) exten=>_xxxxxxxxx*xxxxxxxxx,n,Goto(from-internal,${EXTEN:0:9},2) exten=>_xxxxxxxxx*xxxxxxxxx,n,noop(passing dialing digits ${EXTEN:0:9})

I expect there are more sophisticated ways to break up the ${EXTEN} string which would look for the * instead of using a fixed number of digits.

Thank you for your responce, I have got this working now using contexts.

I already have an outbound route that allows the user to dial a 7 digit number beging in 0 using the _0xxxxxx pattern match, that is attached to the trunk I want to dial from the IVR. This allows users to dial this number (0123456 for example) from with the PBX, get to this trunk and the CID (0123456) gets passed.
I have added a custom context and set all to allow, meaning the outbound route I have setup already can be used.
Now when I dial into the system get connected to the IVR and dial (0123456 for example) the 0123456 number gets passed to the trunk as the To CID.

So thanks for your help on this.
I have not filed a ticket reporting it yet because I am not sure where to do this, could you please post a link to the site where I report it.