# Sort dialing

**URL:** <https://community.asterisk.org/t/sort-dialing/25571>\
**Category:** Asterisk Support\
**Created:** [February 17, 2009, 4:25am UTC](https://community.asterisk.org/t/sort-dialing/25571 "2009-02-17T04:25:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 17, 2009, 4:25am UTC](https://community.asterisk.org/t/sort-dialing/25571/1 "2009-02-17T04:25:09Z")

</div>

Sir,

I have working asterisk 1.4.1 and its working perfectly now i want to create sort dialing no. suppose if any one dial \*123 than it will search from database and in database we have define \*123 represent number 01213291999 and it will dial that number. and i have a program in which we have create sort dialing number and program to search from datafile but i donot know how to pass dialing code to that program and return dialing number which is dialed by asterisk.

Please help how to pass dialing number from asterisk and capture return number.

Rajeev.

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 17, 2009, 8:43am UTC](https://community.asterisk.org/t/sort-dialing/25571/2 "2009-02-17T08:43:37Z")

</div>

I’m not sure, I’ve understood you correctly. So you do smthing like  
/ael syntax/:

```auto
_***XXX*XXXXXXXXXXX => {
    /*here should probably be a test if a number is valid*/
    DB(somedb/${EXTEN:3:3})=${EXTEN:7};
}
```

to store number into database ‘somedb’…

```auto
_XXX => {
    Dial(DB(somedb/${EXTEN}),,);
}
```

to call an entry from database somedb…

?

---

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 17, 2009, 9:35am UTC](https://community.asterisk.org/t/sort-dialing/25571/3 "2009-02-17T09:35:11Z")

</div>

Sir, i want to know search in database and if number found than dial number from database.

Rajeev

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 17, 2009, 12:51pm UTC](https://community.asterisk.org/t/sort-dialing/25571/4 "2009-02-17T12:51:54Z")

</div>

“to search a database” means “to search an AstDB” or you mean some external database engines like MySQL / MSSQL / something\_else ? 😮

---

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 17, 2009, 12:56pm UTC](https://community.asterisk.org/t/sort-dialing/25571/5 "2009-02-17T12:56:25Z")

</div>

in AstDB.

Rajeev.

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 17, 2009, 1:08pm UTC](https://community.asterisk.org/t/sort-dialing/25571/6 "2009-02-17T13:08:04Z")

</div>

So, someones dials 123

```auto
_XXX => {
    Dial(DB(somedb/${EXTEN}),,);
}
```

- will call a number in DB(somedb/123)

❓

---

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 17, 2009, 1:45pm UTC](https://community.asterisk.org/t/sort-dialing/25571/7 "2009-02-17T13:45:03Z")

</div>

Sir,

I am not aware how to create AstDB and how to store number in AstDB will you please guide me step by step how to create AstDB than how to add number in AstDB and how to search and dial number in AstDB.

Thanks for your help and time.

Rajeev

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 17, 2009, 1:59pm UTC](https://community.asterisk.org/t/sort-dialing/25571/8 "2009-02-17T13:59:07Z")

</div>

if you have module app\_db.so (? not too sure) loaded, you’ll get file /var/lib/asterisk/astdb…

using it is very simple:

DB(databasename/somekey)=somevalue will SET value of somekey in database databasename to value somevalue  
you can GET this value at any time - use variable ${DB(databasename/somekey)}

> [@](#):
>
> ex: DB(mobile\_phone/daddy)=33607903469 # will add/modify database “mobile\_phones”, an entry for Daddy = 33607903469
> 
> we can dial it by dialing \*1 (for ex):  
> \*1 =\> {  
> Dial(DB(mobile\_phone/daddy),);  
> }

[voip-info.org/wiki/view/Asterisk+func+db](http://www.voip-info.org/wiki/view/Asterisk+func+db)

Now, please, reread my first post here 😃

---

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 18, 2009, 8:12am UTC](https://community.asterisk.org/t/sort-dialing/25571/9 "2009-02-18T08:12:04Z")

</div>

Sir,

thanks for your help now i am able to understand but only one thing i want to ask how to store number means \*123 represent number 1213291888 and \*1 represent 33607903469  
\*1 =\> {  
Dial(DB(mobile\_phone/daddy),);

mean to say how to store \*123 to represent number 1213291888

Rajeev.

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 18, 2009, 9:33am UTC](https://community.asterisk.org/t/sort-dialing/25571/10 "2009-02-18T09:33:18Z")

</div>

So, if you have

```auto
   _***XXX*XXXXXXXXXXX => {
       /*here should probably be a test if a number is valid*/
       DB(somedb/${EXTEN:3:3})=${EXTEN:7};
   }
```

in your extensions.ael (or something similar in extensions.conf) - if someone DIALs “\*\*_123_1213291888” from his phone, it will set

```auto
   DB(somedb/123)=1213291888
```

---

<div class="post-metadata">

**Author:** ![rajeevsg](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rajeevsg](https://community.asterisk.org/u/rajeevsg)\
**Post date:** [February 19, 2009, 12:29pm UTC](https://community.asterisk.org/t/sort-dialing/25571/11 "2009-02-19T12:29:54Z")

</div>

Sir,

It’s working thanks for your help.

Sir, there is any way to get printout of all store information in astdb.

Rajeev.

---

<div class="post-metadata">

**Author:** ![wowks](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wowks](https://community.asterisk.org/u/wowks)\
**Post date:** [February 19, 2009, 5:23pm UTC](https://community.asterisk.org/t/sort-dialing/25571/12 "2009-02-19T17:23:41Z")

</div>

You can print any variable, using, for example

```auto
   Noop ( ${DB(aaa/bbb)} ); // print to asterisk console if 'core verbose' set >= 3
```

or

```auto
   Verbose (|${DB(aaa/bbb)}); // always print to asterisk console
```
