Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Users might experience few discrepancies in Search results. We are working on this on our side. We apologize for the inconvenience it may have caused.
New Member

Question about script variables (CRS5)

I would like to create a step in my script that collects the ANI, keeps the last 4 digits (everything else stripped), and adds a 3 at the start of the new string.  I'm stuck on a part of this, however, wondering if someone has any idea.

1) My script has the Get Call Contact Info step and is programmed to insert the caller's ANI into a string called ANI.

2) How can I strip the digits in the second step to keep only the last 4 digits?

3) With this newly edited number, is adding a "3" at the start of the string as simple as creating a string value of 3""?

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Question about script variables (CRS5)

Place it where you need it to be converted.  For example, right after the Get Call Contact Info step.

Yes, you are correct, substituting the variable name was the right move.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
Super Bronze

Re: Question about script variables (CRS5)

Hi

You could do it in a 'set' step:

In the first box, set the variable name : DNIS

In the second, : "3" + DNIS.substring(DNIS.length() - 4)

Regards

Aaron

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!
11 REPLIES
New Member

Re: Question about script variables (CRS5)

Sorry, I meant to say DNIS.  I want to manipulate the called number, play a prompt, then redirect to the new extension.

Re: Question about script variables (CRS5)

Last four:

Set variable_name = variable_name.substring(variable_name.length() - 4)

Prepend:

Set variable_name = "3" + variable_name

All in one step:

Set variable_name = "3" + variable_name.substring(variable_name.length() - 4)
Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Re: Question about script variables (CRS5)

Hey Anthony,

     Where is this placed?  Also, I'm calling my string DNIS, so does that mean that your variable_name needs to be changed to

Set DNIS = "3" + DNIS.substring(DNIS.length() - 4)

Re: Question about script variables (CRS5)

Place it where you need it to be converted.  For example, right after the Get Call Contact Info step.

Yes, you are correct, substituting the variable name was the right move.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Re: Question about script variables (CRS5)

Hey Anthony,

     Still confused, this goes after the Get Call Contact Info step, but what kind of step does this go in?  In what do I put this syntax?

Super Bronze

Re: Question about script variables (CRS5)

Hi

You could do it in a 'set' step:

In the first box, set the variable name : DNIS

In the second, : "3" + DNIS.substring(DNIS.length() - 4)

Regards

Aaron

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!
New Member

Re: Question about script variables (CRS5)

You guys are superstars!  Thank you so much, BIG help, this solved my problem.  One last question - what resource can I study to learn these techniques?  What kind of language is this?  What did you guys use to learn them?

New Member

Re: Question about script variables (CRS5)

Nevermind.  I should be reading the Cisco Scripting Development Guide.  Thanks again for your help, guys.  Much appreciated.

Re: Question about script variables (CRS5)

The language is built off of Java.  (That's NOT JavaScript, but Java)

Having a foundational knowledge of programming allows you to get things like this done, quickly and efficiently.  The language is secondary to the "how".

For example, the Java language will tell you "how" to take a substring of another string with the method call .substring(int), but what it wont tell you is, how to only take the last four characters, or that you need to make sure there are at least four characters in the String, or else you will receive a runtime exception called:

java.lang.StringIndexOutOfBoundsException

That will halt your script.  So, what you need to do, even if you can never imagine a world where the DNIS could be empty or shorter than 4 characters, is protect your script with this:

Set DNIS = (DNIS.length() >= 4) ? "3" + DNIS.substring(DNIS.length() - 4) : DNIS

This will only perform the function on DNIS with four or more characters, otherwise it will leave it alone.

One other pro tip:

Don't hard code your values all over your script.  This would be preferable:

Set DNIS = (DNIS.length() >= DNIS_LENGTH) ? DNIS_PREFIX + DNIS.substring(DNIS.length() - DNIS_LENGTH) : DNIS

Where DNIS_LENGTH and DNIS_PREFIX are predefined int/String values respectively.

If you want to have some fun in the editor, try this in a new script file:

Set variable_name = (variable_name == "") ? "prefix" + variable_name : variable_name

Hint: The step will disappear from the script

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Re: Question about script variables (CRS5)

I just missed your response by seconds.  I just posted some questions about this stuff   Anthony, the .substring syntax doesn't seem to be in the Scripting guides.  Is there a better resource I should be reading to understand this?

Re: Question about script variables (CRS5)

Yes, the Java language reference.

What I normally do is google for the Class name, and read what methods are available.

So for substring, I google:  Java String

Then I read the String Class page and browse the methods, eventually landing on .substring(int)

There's other ways to do this, like buying a Java language reference book, or using the expression language editor, so just pick one that works for you and go with it.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
310
Views
10
Helpful
11
Replies
CreatePlease to create content