01-10-2014 02:36 AM - edited 03-14-2019 12:56 PM
Hi Support Community
I am using a script for which i need to route calls based on the Calling Number. If they come from extension 3XXX they go to agents located at 1 site as first priority and if they come from extensions 4XXX they go to another site first. This all works fine with my current setup :
The above is all working good however its all based on callers from an internal extension. I now need allow calls from external sources ( these could be any location - country, landline, mobile etc ). The calling number for these wont be defined for call routing they should just not match a defined extension and are therefore false in the IF statement and sent to the site defined above. I didnt think i would have to change anything on my script but it isnt working for any external callers.
I have 2 different scenarios but both maybe the same solution, an unknown caller cli so populated as '0' in the CallingNumber variable and a correct cli for example 212XXXXXXX which is also populated in the CallingNumber variable. When any external number dials in the script playes 'im sorry we are currently experiencing system problems'. When i debug the script i get the following error :
Exception : For Input String: "212XXXXXXX"; nested exception is: java.lang.NumberFormatException: For input string "212XXXXXXX" ( line:1, col:1)
Any advise would be appreciated.
Carl Ratcliffe
Solved! Go to Solution.
01-10-2014 05:24 AM
Firstly, drkchiloll is correct about NANP exceeding the MAX_VALUE (2147483647) of integers which could cause the exception to be thrown.
Second, why are you processing the number as an integer at all? From the script provided it seems you only have one requirement:
If the area code is 330 the customer location is from New York
If the area code is 331 the customer location is from New Jersey
If either condition above is not true, the customer location is defined as "External"
With that in mind, what you want to accomplish is very simple. Simply extract the area code from the Calling Number, test against those conditions and set your customer variable appropriately.
The first have is easily accomplished via the substring() method, the latter via a Switch STEP as seen below:
One benefit is you are not playing against data types. The other is you are not comparing against a range of numbers which is just sloppy and cumbersome.
Now this is a simple usecase and maybe that's enough for you, but this sets you up for greater expansion. In the event you want to match against, say 100 area codes and assign value appropriately you can begin to leverage external data stores. Be it an XML document, database or otherwise. Imagine putting integer comparisons for 100 area codes; tedious no?
If you go with the above example, make sure to format your number correctly. substring(0,3) may not caputre the area code if you have +1 in front of the number or an access code for instance.
I would like to add, from the above example you may consider testing against the length of CallingNumber before processing substring; for example:
if (CallingNumber.length() > 10)True:
/* process number with substring(); */
False:
/* test against "unknown" number 0 */
if (CallingNumber == "0")
True:
/* external caller with unknown number */
False:
/* probably an internal caller */
Otherwise, substring(0,3) as above would throw an exception on the step if the number was "0".
Which brings me to the last point. Consider putting On Exception GoTo and catching either specific exceptions if you know what they are, or ExpressionException if you do not. From there you can recover from a failure and continue processing.
Best of luck.
Regards,
Tanner Ezell
www.ctilogic.com
01-10-2014 07:44 AM
Carl,
I'm glad to hear it. There should be a simple solution to your matching, instead of
if (CallingNumber == "0")
You could use:
if (CallingNumber == "" || CallingNumber == null)
This will catch bull null values and blank. Catching null is probably not necessary but it does add an additional level of testing.
I suspect you need to move the "On Exception GoTo" step up in your script, right before you call substring() in the SET step.
For substring() you pass along where you want to begin splicing characters from and where you want it to end. As such, CallingNumber.substring(0,3) is saying:
"I want the substring of CallingNumber starting at character 0 and ending at character 3 returned"
If you have the variable, CallingNumber as "3305551234", it looks like this:
CallingNumber[0] = "3"
CallingNumber[1] = "3"
CallingNumber[2] = "0"
CallingNumber[3] = "5"
CallingNumber[4] = "5"
CallingNumber[5] = "5"
CallingNumber[6] = "1"
CallingNumber[7] = "2"
CallingNumber[8] = "3"
CallingNumber[9] = "4"
Note as you might notice, CallingNumber[3] is not included. That is because according ot the definition of substring(startIndex, endIndex), startIndex is inclusive (meaning it is included in the return) and endIndex is exclusive (meaning it is not included in the return).
I hope this has helped shed some light on what is happening.
Regards,
Tanner Ezell
www.ctilogic.com
01-10-2014 04:05 AM
Is there any way you can provide a testable script by pulling the relevant steps out of your current script and providing them here?
01-10-2014 04:17 AM
Hi, please see attched script. All the relevant information is included.
Basically if CallingNumber is 330XXXX it works correctly ( routes to a CSQ that isnt in the script ), the same goes for a CallingNumber of 331XXXX.
Any external CLI ( populates CallingNumber correctly ) or unknown number fails at the set step 'CallingNumber_INT'.
Thanks, Carl
01-10-2014 04:53 AM
For Unknown number I don't see problems if the CallingNumber Variable is actually "0". Can you actually Confirm this?
Regardless, try the attached file and verify it operationally. What makes me uneasy about the String Number Conversion is external numbers can be so close to "overflowing" your INT that I wouldn't use that DataType at all (use LONG). What I provided will work with UNKNOWN as well because I'm using a TRY/CATCH Block that will Throw the NumberExceptionFormat Exception..but continue processing..and the LONG will be set to a value of 0..Let me know if this helps..
01-10-2014 05:24 AM
Firstly, drkchiloll is correct about NANP exceeding the MAX_VALUE (2147483647) of integers which could cause the exception to be thrown.
Second, why are you processing the number as an integer at all? From the script provided it seems you only have one requirement:
If the area code is 330 the customer location is from New York
If the area code is 331 the customer location is from New Jersey
If either condition above is not true, the customer location is defined as "External"
With that in mind, what you want to accomplish is very simple. Simply extract the area code from the Calling Number, test against those conditions and set your customer variable appropriately.
The first have is easily accomplished via the substring() method, the latter via a Switch STEP as seen below:
One benefit is you are not playing against data types. The other is you are not comparing against a range of numbers which is just sloppy and cumbersome.
Now this is a simple usecase and maybe that's enough for you, but this sets you up for greater expansion. In the event you want to match against, say 100 area codes and assign value appropriately you can begin to leverage external data stores. Be it an XML document, database or otherwise. Imagine putting integer comparisons for 100 area codes; tedious no?
If you go with the above example, make sure to format your number correctly. substring(0,3) may not caputre the area code if you have +1 in front of the number or an access code for instance.
I would like to add, from the above example you may consider testing against the length of CallingNumber before processing substring; for example:
if (CallingNumber.length() > 10)True:
/* process number with substring(); */
False:
/* test against "unknown" number 0 */
if (CallingNumber == "0")
True:
/* external caller with unknown number */
False:
/* probably an internal caller */
Otherwise, substring(0,3) as above would throw an exception on the step if the number was "0".
Which brings me to the last point. Consider putting On Exception GoTo and catching either specific exceptions if you know what they are, or ExpressionException if you do not. From there you can recover from a failure and continue processing.
Best of luck.
Regards,
Tanner Ezell
www.ctilogic.com
01-10-2014 06:29 AM
Thank you Tanner
I will take a look at your recomendations and test.
Carl
01-10-2014 06:31 AM
Thank you also drkchillol
01-10-2014 07:16 AM
Hi Tanner
I have implemented your advice and it works great using the substring and switch step. So much easier than matching ranges which is as you said cumbersome and sloppy.
I still have a query regarding the unknown number cli's. The CallingNumber is actually blank so "" not "0" as i previosuly mentioned. I tried to put a step of "on exception go to" after the set sAreaCode step and use a label to redirect the traffic but this throws up an exception in the script when i debug, not sure if iv implemented that correct ?
Also can you advise what the 0 is used for in the substring command you provided CallingNumber.substring(0,3)
Thanks, Carl
01-10-2014 07:44 AM
Carl,
I'm glad to hear it. There should be a simple solution to your matching, instead of
if (CallingNumber == "0")
You could use:
if (CallingNumber == "" || CallingNumber == null)
This will catch bull null values and blank. Catching null is probably not necessary but it does add an additional level of testing.
I suspect you need to move the "On Exception GoTo" step up in your script, right before you call substring() in the SET step.
For substring() you pass along where you want to begin splicing characters from and where you want it to end. As such, CallingNumber.substring(0,3) is saying:
"I want the substring of CallingNumber starting at character 0 and ending at character 3 returned"
If you have the variable, CallingNumber as "3305551234", it looks like this:
CallingNumber[0] = "3"
CallingNumber[1] = "3"
CallingNumber[2] = "0"
CallingNumber[3] = "5"
CallingNumber[4] = "5"
CallingNumber[5] = "5"
CallingNumber[6] = "1"
CallingNumber[7] = "2"
CallingNumber[8] = "3"
CallingNumber[9] = "4"
Note as you might notice, CallingNumber[3] is not included. That is because according ot the definition of substring(startIndex, endIndex), startIndex is inclusive (meaning it is included in the return) and endIndex is exclusive (meaning it is not included in the return).
I hope this has helped shed some light on what is happening.
Regards,
Tanner Ezell
www.ctilogic.com
01-10-2014 08:03 AM
Thank you very much Tanner for taking time to give a great explaination and solution. Carl Ratcliffe
01-10-2014 09:40 AM
I prefer the .startsWith(s) method over the .substring(0, n) method.
Anthony Holloway
Please use the star ratings to help drive great content to the top of searches.
01-10-2014 10:35 AM
TRUE
(but not really)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide