Remove excess digits from incoming DID

I am currently using FreePBX with a small amount of extensions. The system is used to connect to a larger PBX (supporting hundreds of phones). When a call comes in (over a ZAP connection) from an extension on the other PBX, it comes with the DID of the internal extension with extra 0’s added at the end. For example, 3503 would come in as 3503000000. Outside calls come in the standard 1112223333 format (still forwarded through the other PBX). Is there a way to setup a conditional statement where if the last 6 digits are “000000” to remove those digits?

I’ve seen this line which I modified, but not sure how to set it up, or where to add it.

exten => _.,n,Set(DID=${IF($["${EXTEN:4:10}"=“000000”]?s:${EXTEN})})

I am not an expert, and have played around with Asterisk a bit, but don’t know all the commands. I am wondering if there is a way to do this in the GUI, or should I add it manually into the override file?

Any help or guidance would be appreciated.
Thank you,

I looked at the above link earlier, but it only talked about removing digits at the beginning. I did however find out how to do it:

I added the following line to my from-dihdi in extensions_additional.conf:

exten => s,n,Set(CALLERID(num)=${IF($["${CALLERID(num):4:6}"=“000000”]?${CALLERID(num):0:4}:${CALLERID(num))})

However, I am not sure if this is the best location to put this. Will updates or configuration changes reset this file, or will it remember this now?

This works great for what I needed, and now, to work on an LDAP lookup so I know who’s calling.

extensions_additional.conf is rewritten each time you do an “orange bar reload” so your changes will be lost. The place to put them is in extensions_custom.conf. What you want to do is look at the trunk settings for the trunk the calls are coming in on and see where the context= statement is pointing to. Normally it is from-trunk, so in that case you can add something like this to extensions_custom.conf:

exten => _X!,1,Set(CALLERID(num)=${IF($["${CALLERID(num):4:6}"=“000000”]?${CALLERID(num):0:4}:${CALLERID(num))})
exten => _X!,n,Goto(from-trunk,${EXTEN},1)
exten => h,1,Macro(hangupcall,)

Note that due to its length, the second line may be broken into two lines in this post, so make sure it’s only one line in the actual custom context.

After you have added the above, then you change the trunk context= statement to point to the new context, in this case from-trunk-modifycid. If for some reason the trunk context was pointing to something other than from-trunk, then replace from-trunk in the custom context with whatever was originally in the trunk setting. FreePBX will not overwrite anything in extensions_custom.conf.

I am using a zap interface. I don’t have the settings in FreePBX where I can change the context of that interface. Are they hidden away somewhere? I have that on a separate SIP trunk, where you can fill out a text box, but haven’t seen it for the zap interface.

I found where I add that, in zapata.conf. I added the custom like you mentioned, and then continued it on. Now when I make changes, it doesn’t overwrite them, and doesn’t appear to touch zapata.conf. Thank you!

You’re welcome. Glad to hear you figured it out. I don’t have an zaptel/dadhi trunks, so I didn’t know exactly how you’d need to do it, but sound like you’re nailed it!