Set Outbound CID for specific Extension via CLI / Database Edit

Hi there.

Been searching the web for quite some time trying to figure out how to update an extensions Outbound CID and Name via a database change / CLI.
image

We have a few numbers and specific users need to call out on different numbers for different reasons. I’ve created a small online web portal for managing our system. Seeing call logs, usage, etc. I would like to be able to allow my users to change their caller ID for their extension via a dropdown in the online portal I made in PHP.

So far I’m able to change the CID in the asteriskdb.users table but when I try pushing the ‘fwconsole reload’ or the 'amportal a r ’ it appears to apply the changes, and when I check in FreePBX it even changed the Outbound CID for the specific extension in the field, but the CID doesn’t actually change when placing a call. When I check the users table again the change is there, and the changed CID persists after doing an ‘apply config’ in freePBX to some other portion but still the CID doesn’t change. If I change the outbounbd CID to something inside FPBX and apply the config, or even hit ‘submit’ and then ‘apply config’ after my web app made the change, then the CID is changed successfully and can place a call out with the changed CID.

I also made a function for my users to add or remove themselves from a ring group using the same exact functions and that works flawlessly.

I’m missing something obvious I know it, just need a little help.

Thanks in advance!

PBX Version:
15.0.17.24

PBX Distro:
12.7.8-2012-1.sng7

Asterisk Version:
16.16.2

What exactly do you meen by “asteriskdb.users table” ?

It exists in neither the mysql databases (asterisk and asteriskcdrdb) nor the sqlite3 /var/lib/asterisk/astdb.sqlite3 database

When I make a call, the outbound CID for the extension is set by this statement in macro-outbound-callerid:
exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${AMPUSER}/outboundcid)})
Confirm (in your Asterisk log) that this is the same for you. Confirm that you have set it properly.
At the Asterisk command prompt, type
database show AMPUSER/1234/outboundcid
and you should see the entry for extension 1234.

However, what you are doing seems (to me) an error prone and inefficient workflow. Some examples:

If a user makes calls on behalf of a few different people, departments or organizations, I’d give him an extension for each, on separate line buttons. He’d press the corresponding line button for his call. Callbacks made from device history or contacts would automatically choose the correct ‘line’.

If you have local numbers in many cities, you might prefix the incoming caller ID to indicate which DID was called, and use that prefix to select the outbound CID. It could have mnemonic value, e.g. 0212 for your New York office and 0415 for San Francisco.

If you are an answering service and need to call on behalf of your customers, set up custom dialplan that integrates with your CRM to pull the correct number from the database.

Describe your application in some detail and we may be able to find a way to automate this.

So sorry, just the asterisk.users

Synchronously you can set the sqlite3 asteriskdb (but only wrap that is an rasterisk -x 'database . . . .' call), asynchronously you can modify the mysql database but it will need an fwconsole reload.

@Stewart1 Thanks for the reply!

The CID change does not happen that often. Basically we have some users who manage multiple departments of a company but never receive incoming calls unless the receptionist transfers the call to their extension. However when they make calls, they are usually only using one outbound number for the majority of the time but on some occasions they switch gears and call out for a different department. (All the same city.) I thought of line keys and setting up separate lines but these users have all their BLF and quick dial keys filled to the brim. Your idea with having different extensions for each makes sense for sure but the big boss said that switching the CID is how he wants it done. :joy:

I have created a drop down list that only allows specific users of the web app to change to specific numbers they are permitted to use. (not letting them edit the CID at will)

@dicko
That’s what I think I’m doing, I have the change go into the mysql database and the weird thing is the CID change reflects in the FPBX gui when I look at the extensions outboubnd CID after changing it in the webapp but it doesn’t apply even with a fwconsole reload. So, when I change it in the web app, go and look in FPBX, the change is there in the Out CID field, but when I make a call, it is the last CID used. If I submit the change in FPBX after the web app changes it and apply config, then making a call out has the changed CID.

try from a shell

rasterisk -x ‘database put AMPUSER/1234 outboundcid “USA GOV <2024561414>”’

it should be immediate, updateing the background mysql database takes longer and a stately reload, be aware that your rasterisk changes are ephemeral until a fwconsole reload

Thanks for the swift reply!

That did work immediately and displayed the CID on an outgoing call to what I set it as.

I am looking to be able to have it set permanently until the user decides to change it back. Are you aware of a way to edit the extensions CID and Display Name and have it update the mysql asterisk.user table and persist through a reload? I’ve tried updating outboundcid on the user table and it doesn’t apply after a fwconsole reload, but does show up in the FreePBX console.

Also thank you for your dedicated assistance and answering all my uneducated questions.

Then you need to do both, set up the sqlite3 database that asterisk uses for immediate effect, then set up the mysql asterisk.users database outboundcid record to be copasetic, then after work hours a fwconsole reload and you should be good to go tomorrow.

1 Like

Thanks, that makes sense.

For my understanding, what does the freePBX editing the extension outbound CID and Display name do that makes that change immediate after the ‘Apply config’?

Basically I’m looking to have the change be immediate, and permanent, and reflect in my webapp until changed again exactly like the FPBX edit extension does after a ‘submit’ and ‘apply config’?

It works for me, but perhaps you need to check your mysql quoting is functional and took hold after a mysql update query , single and double and escaping and allsorts can get your kickers in a twist :wink:

Just thinking, It is quite possible that an EndPoint Manager’s idea of a phone might need to be re- generated as to it’s local display. (Not a big problem with my EPM though, it regenerates on a sync)

Lol. My kickers are definitely twisted. :joy:

Upon further inspection, it looks like the rasterisk database command applied it to the FMFM External CID configuration. Which works? but not how I’m expecting it to.

I am looking to only change the outbound CID and Display Name as shown in the extension edit page under general tab.

Something I found is when I do the following:

  • Change the Outbound CID in my web app which changes it in the mysql asterisk.users
  • Hit my save button which updates the database and then runs fwconsole reload.
    If I make a call at this stage, the CID is not changed.
    If I open up the GUI for FPBX and look at the extension I changed, the Outbound CID is changed to the CID I changed it to in the web app. So it’s making it into the database(?) also if I show that table directly in the db it reflects the change as well
    However, when making a call it does not display the changed CID. But, if I hit the submit button in FPBX (where it is showing the updated CID from the web app) then it applies the Changed CID and I can make a call with the changed CID (note that I do not click the “Apply Config” button when it pops up which is strange to me as if I were to edit the outbound CID and hit submit but not Apply config, it wouldn’t update the CID)

Asterisk itself ONLY uses the sqlite3 database for how it purports itself , FreePBX generally rewrites that ONLY on a forced fwconsole reload . Thus submitting changes will also then need the reload command before any changes percolate down to the sqlite3 database that asterisk uses.

Thank you for all your help and pointing me in the right direction!

I figured out a way that works exactly how I want it to to change the CID via CLI / editing the mysql Database directly:

For the CID Number I set

rasterisk -x ‘database put AMPUSER/1234 outboundcid "5555555555”’

and to change the Display Name ID

rasterisk -x ‘database put AMPUSER/1234 cidname "Display Name”’

Then to make sure that the change was reflected in FreePBX I set:

 UPDATE users SET name = '{$name}, outboundcid = '{$number}' WHERE extension = '{$ext}';

and then I ran the

fwconsole reload

Though it seems unnecessary to run the fwconsole reload as it all works and stays applied and everything is working perfectly! (I could be doing something wrong, but it works so don’t fix it right?)

I just set a check to make sure that the numbers are in our trunk providers account (no spoofing thank the lord for the new STIR/SHAKEN requirements)

Thank you both so much for your help!

Technically the full format of outboundcid is "your name" <yournumber> but it will work fine with just a number in which case callerid(name) will re-use callerid(num), display name is used for internal calls.

fwconsole reload is unneccesary here as you did it manually already and it will also run next time you press the orange bar or restart fwconsole.

Glad you fixed it to your satisfaction.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.