Select Trunk based on Extention's CallerID

I am new to FreePbx and not a SIP expert, I hope I’ll be able to explain myself clearly and use the right terms.

Our FreePBX acts as a gateway between a CRM application and several VoIP trunks. The CRM application is registered on the FreePBX through a single Extension (this is a requirement of the setup).
The calls dialed by the CRM cannot have special prefixes/suffixes to decide the outbound trunk (another requirement).
What I am trying to achieve is to have the CRM place calls with different CallerIDs, and use that to match the rule for the outbound trunk.
In the tests I have done so far the CDR always reports as CNUM/CNAM the extension number, not the VoIP outbound number that I can set in the CRM. It seems that this information is lost because the Extension info overrides it.

Is there a way to use the CallerID from the CRM in the outbound rules?

Thank you
-E-

If you set up the CRM as a trunk, rather than an extension, but with context=from-internal, then the caller ID from the CRM should be passed to the outbound trunk. If you really need to select among different trunks, e.g. they are for different entities and billed separately, then I believe (though haven’t tested) you can use the CRM’s caller ID to qualify the Outbound Route and (if needed) have the Outbound Route or trunk specify a different caller ID to be seen by the called party.

Thank you @Stewart1 for your valuable help. I created a Trunk adding in the User detail section the context:

context=from-internal

I can see the calls in the CDR with the correct CallerID, but for some reason they do not go out through the designed trunk.
Here are the details (full numbers shadowed), maybe you can figure out with is wrong.

Time | Event | CNAM | CNUM | ANI | DID | AMA | exten | context | App | channel | UserDefType | EventExtra
2014-07-09 12:59:35 | CHAN_START | 06678 | DEFAULT | 34592 | from-sip-external | SIP/192.168.1.40-000069b7
2014-07-09 12:59:35 | ANSWER | 06678| 06678 | 34592 | DEFAULT | s from-sip-external | AnswerSIP/192.168.1.40-000069b7
2014-07-09 12:59:44 | HANGUP | 066
78 | 06678 | 34592 | DEFAULT | h from-sip-external |
SIP/192.168.1.40-000069b7
2014-07-09 12:59:44 | CHAN_END | 06678 | 06678 | 34592 | DEFAULT | h from-sip-external |
SIP/192.168.1.40-000069b7
2014-07-09 12:59:44 | LINKEDID_END | 066
78 | 06678 | 34592 | DEFAULT | h from-sip-external |
SIP/192.168.1.40-000069b7

Thank you in advance
-E-

I don’t know why you are seeing from-sip-external. Please post a log of a failed call, including SIP debug.

Hi,
I came up with a solution. In facts we have 2 SIP trunks registered with the same VoIP provider, one of those is GNR (multi number) while the other is single number. It seems that the context is just one per provider IP, taking as valid the first trunk in the list. Hence the second context was shadowed by the first.
Changing the order of the trunks, or disabling the one with the different context, or setting the same context for both trunks solved the problem.
Thanks for your support
-E-