FreePBX and the CID for calls forwarded by the handset

Hi All

I’ve been working on this for days and don’t have a solution yet.

Here’s the scenario: Incoming Call from Party A, goes directly to an extension Internal B. The extension, a Yealink T48G handset, is set to forward the calls to an external number, Party C.

When the call is forwarded, I can see in the output of asterisk -vvvvvxr, that it is setting the Caller ID to be Party A’s (ie: the original caller), when the call is forward out our trunk. Our carrier does not allow foreign CIDs, so it strips it off and replaces it with our main number.

Each extension, including Internal B, has an “Outbound Caller ID” set in FreePBX.

The trunk is set to “Block Foreign CIDs”.

My understanding is, based on our trunk settings, the Outbound CID of the extension should be used. But that is not the case.

Am I missing something?

Here is the output of Asterisk:

In that call Ive attached logs for, the numbers are:

0404847356 (incoming from)
0872219229 (number called)
0882540600 (forward to)
0884708909 (trunk CID)

The call is being sent with the trunks CID. If I remove that setting from the trunk, it will send 0404847356 as the CID.

What we want is 0872219229 (the extensions CID) to be presented as the CID to 0882540600.

This is probably not the “correct” solution, but I found that CALLERID(rdnis) contains the original number called if its a forwarded call.

So, adding this to extensions_custom.conf does work:

exten => s,22,NoOp(RDNIS is ${CALLERID(rdnis)} with length ${LEN(${CALLERID(rdnis)})})
exten => s,23,ExecIf($[${LEN(${CALLERID(rdnis)})} != 0]?Set(CALLERID(all)=${CALLERID(rdnis)}))

I’d still like to understand why the Block Foreign CIDs isn’t working as I’d expect it to.


Doubt it. Most of the time, the trunk CID will be used unless you specify the route as an Intracompany route.

Never mind. Your outbound caller ID will always be set by your provider.

You need to add an “outbound for cell calls” provider that allows foreign CID. This way, you can set the CID to the extension or the original caller’s CID, or the 800 number for PornHub - it just wouldn’t matter.

The point here is exactly that. We can’t set the CID to what the inbound callers number is, nor do we want to.

Even if our carrier did allow us to do that, we still want the forwarded call to have the outbound CID of the handset that is actually forwarding the call. Its the only way for our people to know which department the inbound caller called. Which is important in this use case.

My solution shown above does work perfectly. Which ever number the outbound caller called is whats presented as the CID on the forwarded call. And because we own that number, our carrier allows it.

Looks like you have a working solution, and I doubt it can be done any easier than what you are using now, but I’m not convinced that using the [macro-outbound-callerid-custom] is the best way to do this. There is a context reserved specifically for users to define code for outbound calls, and that is [ macro-dialout-trunk-predial-hook].