Help scripting complicated callerid setup

Recently changed to SIP from Primary Rate using the same provider. The provider now requires callerid presentation to accept the call using sip (previously on PRI it defaulted back to the primary line ID). They only accept numbers which we own on the trunk.This is a problem when simultaneously ringing cellphones or forwarding calls as our PABX sends the original ID as callerid.

If the current caller ID is not part of our range I am wanting to set it to a standard number (old ISDN primary line number).

Don’t really know where to start as this is a bit beyond my level of Asterisk. I think I need to write a loop of cascading if statements but I am not sure how to do so.

Any help or pointers in the right direction would be greatly appreciated!!


core show application set
core show function CALLERID


Asterisk ex-girlfriend logic.

Figured it out:

For people who get in my predicament:

The following in your call out area:

exten => _X.,1,GoSub(callerid-update,${CALLERID(num)},1)


exten => +649359XXXX,1,Set(CALLERID(num)=${CALLERID(num)})
exten => +64XXXXXXXX,n,Return()
exten => _X.,1,Set(CALLERID(num)=+64XXXXXXX)
exten => _X.,2,Return()
exten => i,1,Return()