Showing results for 
Search instead for 
Did you mean: 

Area Code routing in UCCX script



I need suggestion of the best way to route the calls base on Area Code in UCCX script. I need to build the script that can validate the area code and if this is US area code send call to US queue and if this is Canada area code to send call to Canada queue, and if no area code recognized send it to the menu and ask if the caller from US or Canada.

My script is reading the area code and send it to sub flow to check in XML file first if this is Canada  and if not send it to second sub flow and check in XML file if this is US. This is working but I am worry that list of US Area Codes is very long list and takes about 300 steps.

Is some one can suggest the better way to set it up.

Thank you


VIP Advocate VIP Advocate
VIP Advocate

I've not checked this, but is there a range you can collapse this into? Like 200-299 = USA, which would reduce your steps.

I've seen pretty big scripts, I really don't think 300 steps is bad, but any optimization now will save you headaches tomorrow.


This is where XPath comes to your rescue. You can create an XML document, or perhaps use the one you already have depending on the structure, and then have the CCX script query the XML file in a single step. No need to loop through every row in the XML file.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <npa uid="404">us</npa>
  <npa uid="608">us</npa>
  <npa uid="416">ca</npa>
  <!-- etcetera -->

In the AEF script, just use a Get XML Document Data step with a properly structured XPath statement. Continuing the example: 

"/nanp_npa_assignments/npa[@uid='" + triggeringContactAreaCode + "']/"

which will be concatenated at runtime to look like this:


Take note of the combination of a single and double quote here. The double quote is part of the String concatenation while the single quote is part of the XPath statement.

The variable triggeringContactAreaCode is the NPA you have parsed out of the ANI using some other method such as a nested if statement based on the leading character and length. Example:

if ((triggeringContactCallingNumber.length() == 12) && ((triggeringContactCallingNumber.startsWith("+1")) || (triggeringContactCallingNumber.startsWith("91")))) {
triggeringContactAreaCode = triggeringContactCallingNumber.substring(2,5);
else if ((triggeringContactCallingNumber.length() == 11) && (triggeringContactCallingNumber.startsWith("1"))) {
triggeringContactAreaCode = triggeringContactCallingNumber.substring(1,4);
} else if (triggeringContactCallingNumber.length() == 10) {
triggeringContactAreaCode = triggeringContactCallingNumber.substring(0,3);
} else {
triggeringContactAreaCode = "";

If the area code is not found then the result variable of the Get XML Document Data step will be given a null value. At that point you can use a Switch step (aka Match Case) to decide how to proceed:

Match Switch (nanpNpaAssignmentResult.toLowerCase()) {
  Case: "us"
    // US caller logic
  Case: "ca"
    // CA caller logic
  Case: Default
    // Unknown caller logic - play a menu

Finally, you can get a list of the active area codes here:


Excellent Guide, here's an example script finding the area code and doing the XML file lookup.

Another cool way specially if you're looking to know carrier or if it's a mobile number would be to do it via API using something like There is a cost though, but looks very easy to use.



If you just want to know if it's Canada, or US, or niether - then
couldn't you just create a comma-separated string of all the Canada area
codes, and another of all US area codes?  Then just use a simple IF
statemet to check if the Canada-string *contains *the caller's area code
(or if index-of(areaCode)>=0)
If not, check if the US-string contains the caller's area code?
Since it's always 3-digits, then you need not worry about lookups or

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: