I was unable to simply rewrite the CDR destination, because ‘dst’ is read-only in the Asterisk CDR function. However, this code:
[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Setting CDR userfield to ${DIAL_NUMBER})
exten => s,n,Set(CDR(userfield)=${DIAL_NUMBER})
exten => s,n,MacroExit()
added to extensions_custom.conf (using Admin → Config Edit) did put the number sent to the trunk into the CDR Userfield, which may be adequate for your application. If not, you could explicitly update the database from the dialplan or post-process the CDR file. Or, another member may know of a way to do this easily.
Why is that? Is there a good reason why you can’t just dial 99998888? In most places, that works out better. These days, numbers are rarely dialed manually. We have CRM systems, company directories, contact lists, click-to-call, speed dials, etc. If your Contact entry for John Doe is 099998888, then when he calls, his caller ID will be 99998888 and won’t match, so his name won’t be displayed. And if you try to call him back from your phone’s Call History or Missed Calls, the call won’t go through.
If your country has short codes for large organizations and government agencies, you could require an initial 0 just for those. For example, in Thailand we call for McDonald’s delivery on 1711 http://mcdelivery.mcthai.co.th/promotion.php . That would conflict with your extension 1711, so your system in Thailand might require dialing 01711 for McDelivery, but ordinary landlines and mobiles could be dialed without prefixing a 0.
Next, when do you dial 29999888 for an alternate trunk? If that’s just rarely, e.g. to work around a problem, it’s not an issue. But if you do it regularly to select the best route to a specific destination, IMO that’s better handled by Outbound Routes, so your users don’t have to think about it (and make mistakes). If it’s e.g. to change the outbound caller ID because you make and answer calls for multiple organizations, IMO that’s better handled by using multiple line appearances on the phones (select Line 1 to call from Acme Widgets, Line 2 to call from Awesome Hosting).