> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/route-order-tutorial.md).

# route order Tutorial

### route\_order tutorial

'route\_order' is a method implemented in the base\_routing and is use to order routes. This tutorial will explain how to use the parameter for the 'route\_order' method.

#### route\_order examples

***

Things to know about these examples:

* The :show\_route\_order method print in the output window the order of the naps.
* A new field called 'priority' needs to be add to the routes.
* This script will not find any route match, therefore dropping the call.

**route\_order setup**

Routes to order:

```
Calling      Called      NAP      Remapped NAP       Priority
5550000     2220000     sip_p1     isdn              4
5550000     1110000     sip_p3     sip               3
5550000     3330000     sip_p2     isdn_1            2
```

Nap list:

```
Name
sip_p1
sip_p3
sip_p2
```

The call and naps input in the test script window:

```
@call_params = {:calling => '5550000', :called => '5550002', :nap => 'sip_p3'}
@nap_list = [
{:name => 'sip_p3'},
{:name => 'sip_p2'},
{:name => 'sip_p1'}
]
```

#### :route\_field\_name parameter

***

**:route\_field\_name script example**

Here how it can be order using the ':route\_field\_name' argument. The example script will order the routes by priority.

```
require 'base_routing'

class SimpleOrdering < BaseRouting
route_order :route_field_name => :priority
route_match :method => :show_route_order

def show_route_order( route, call, nap_list )
@local_name = "N/A"
@local_priority =  "N/A"
route.each do |key, value|
case key.to_s
when "remapped_nap"
@local_name = value
when "priority"
@local_priority = value
else
```

1. puts "key = #{key}, value = #{value}" end

   end puts "Nap name:#{@local\_name}, priority:#{@local\_priority}"

   return true end

   end

   @@routing = SimpleOrdering.new

   def init\_routes( routes ) @@routing.init routes end

   def route( call, nap\_list ) puts "This script should put all the route priority order starting with the lowest." @@routing.route call, nap\_list end

**:route\_field\_name script output**

This script will not find any route match, therefore dropping the call, but it will print in the output the route ordered according to their priority. The output should look like this (if tried in the test script window).

```
OUT: This script should put all the route priority order starting with the lowest.
OUT:
OUT: Nap name:sip_p2, priority:2
OUT:
OUT: Nap name:sip_p3, priority:3
OUT:
OUT: Nap name:sip_p1, priority:4
OUT:
```

#### :method parameter

***

**:method script example**

Here how it can be order using the ':method' argument. The example script will order the routes alphabetically by nap. The example script will order the routes alphabetically by nap just like the 'proc' example.

```
require 'base_routing'

class SimpleMethodOrdering < BaseRouting
route_order :method => :nap_alphabetical_order
route_match :method => :show_route_order

def nap_alphabetical_order( routes, nap_list )
@tmp_routes = routes.sort {|x,y| x[:nap] <=> y[:nap] }
end

def show_route_order( route, call, nap_list )
@local_name = "N/A"
@local_priority =  "N/A"
route.each do |key, value|
case key.to_s
when "nap"
@local_name = value
when "priority"
@local_priority = value
else
```

1. puts "key = #{key}, value = #{value}" end

   end puts "Nap name:#{@local\_name}, priority:#{@local\_priority}"

   return false end

   end

   @@routing = SimpleMethodOrdering .new

   def init\_routes( routes ) @@routing.init routes end

   def route( call, nap\_list ) puts "This script should put all the route priority order starting with the lowest." @@routing.route call, nap\_list end

**:method script output**

This script will not find any route match, therefore dropping the call, but it will print in the output the route ordered alphabetically by nap. The output should look like this (if tried in the test script window).

```
OUT: This script should put all the route priority order starting with the lowest.
OUT:
OUT: Nap name:sip_p1, priority:4
OUT:
OUT: Nap name:sip_p2, priority:2
OUT:
OUT: Nap name:sip_p3, priority:3
OUT:
```

#### :proc parameter

***

**:proc script example**

Here how it can be order using the ':proc' argument. The example script will order the routes alphabetically by nap just like the 'method' example

```
require 'base_routing'

class SimpleProcOrdering < BaseRouting
route_order :proc => Proc.new { |routes, nap_list|
@tmp_routes = routes.sort {|x,y| x[:nap] <=> y[:nap] }
}
route_match :method => :show_route_order

def show_route_order( route, call, nap_list )
@local_name = "N/A"
@local_priority =  "N/A"
route.each do |key, value|
case key.to_s
when "nap"
@local_name = value
when "priority"
@local_priority = value
else
```

1. puts "key = #{key}, value = #{value}" end

   end puts "Nap name:#{@local\_name}, priority:#{@local\_priority}"

   return false end

   end

   @@routing = SimpleProcOrdering .new

   def init\_routes( routes ) @@routing.init routes end

   def route( call, nap\_list ) puts "This script should put all the route priority order starting with the lowest." @@routing.route call, nap\_list end

**:proc script output**

This script will not find any route match, therefore dropping the call, but it will print in the output the route ordered alphabetically by nap. The output should look like this (if tried in the test script window).

```
OUT: This script should put all the route priority order starting with the lowest.
OUT:
OUT: Nap name:sip_p1, priority:4
OUT:
OUT: Nap name:sip_p2, priority:2
OUT:
OUT: Nap name:sip_p3, priority:3
OUT:
```

***

Back to [Routing Script Tutorial](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/routing-script-tutorial/README.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/route-order-tutorial.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
