A couple of days ago two gentlemen in these forums helped me work out a scritping problem. I want to learn more about scripting expressions but would like some advice. I'm working through the Scripting and Development Series volumes (which can be daunting to someone who doesn't do any programming) to reverse engineer syntax that was suggested to me.
I want to know why this syntax works.
My original problem was that I wanted to take a 5 digit extension coming into the call center, keep the last 4 digits and replace the first one with a "3". This line, combined with the appropriate variable and placed in a "set" step does the trick;
"3" + DNIS.substring(DNIS.length() - 4)
So, knowing what I do about the problem, I understand what this does. A "3" + at the start of this syntax means that the character will be prepended to the final output. Fair enough. There are two modifiers that I would like to learn more about. The ".length" modifier is described on page 95 of volume 3. While .substring makes intuitive sense, I can't seem to find it in the documentation. How would l otherwise know that this syntax is available?
In parenths, the syntax is telling us that the DNIS variable's length will be "- 4". Two questions - 1) Is this necessarily always going to be right-justified? What if I wanted to keep the first 4 instead of the last 4, how would that look? Also, what do the "()" characters do? Where can I turn to find an explanation?
Or, am I missing the boat completely and this syntax was put together with the drop-downs?
All of these are simple Java methods so most public Java 1.4.2 documentation will work. The most valuable addition would be some basic programming knowledge as Java is just another language. The CCX Editor is just absracting some of the Java beans code through drag-and-drop steps for you.
The String substring method allows you to choose a start and stop position as well. In the example you were given it was right-justified only because the start position defined was the last position of the variable value. This could as easily be DNIS.substring(0, 2) to copy the first three characters.