03-10-2020 04:00 AM
Hello,
Newbie here. Can someone provide me an example on how to assign a value to an array? What step should i be using? I have tried Set method but there is no way to give the position of the array.
Thanks in advance.Contact Center, UCCX, Other Contact Center
03-10-2020 05:02 AM - edited 03-11-2020 01:35 AM
There are likely multiple ways to do this, but this is how I've done it in one script.
Variables
{
int i = 0;
for (i = 0; i < strTestNumberArray.length; i++)
if (DNIS == strTestNumberArray[i])
{
strTestNumber = DNIS;
break;
}
}
03-10-2020 11:18 AM
03-10-2020 12:12 PM
Have a look at this post, https://community.cisco.com/t5/contact-center/splitting-a-string-variable-in-uccx/td-p/2296746, it might help.
03-10-2020 02:15 PM
03-11-2020 01:38 AM - edited 03-11-2020 01:47 AM
@Anthony Holloway wrote:
It looks like you have a character, possibly the semi-colon, at the end of your expression. The compression of the image is too high to tell for sure, but there shouldn't be any characters after the last parenthesis )
@Anthony Holloway Sharp eyes as always. I agree it does look like there is a semi-colon at the end of the expression.
@Nliya53887 Please update your expression to not have any characters after the last parenthesis to see if that corrects your problem.
03-11-2020 10:42 AM
03-11-2020 11:45 AM
03-10-2020 12:12 PM
...adding a few sample use cases with variables of type String - Array
1. Uses a 'switch' and loop to add individual elements to the array:
2. Uses a 'Set' statement with a '.split' string function to assign all elements to the array variable (then '.trim' String in a loop to remove extra spaces):
I will attach (attempt to attach...) the sample scripts zipped. You can use the 'step over' button in the editor control pane to evaluate how these work.
These are intended only as sample methods to help generate ideas on how to initialize and use an array in UCCX. I'm sure there are more methods to do this...
Hope this helps.
-Sean
03-11-2020 10:41 AM
03-11-2020 01:44 PM - edited 03-11-2020 01:49 PM
03-11-2020 02:13 PM - edited 03-11-2020 02:19 PM
1) The entire JSON Path is a String, right? So, in order to slip the loop counter (iArrayElement) into the String, you need to do something called String Concatenation. In Java, that's as simple as using the plus sign (+) to combine things together.
E.g.,
"$.QueryContractsBySiteIDResult.Contracts[" + iArrayElement + "].CoveredManufacturers[" + iArrayElement + "]"
Also, if we saw the JSON document, there might be an easier way to get the data from it. Something doesn't seem quite right about this approach.
2) Like I just said in response to #1, there's got to be an easier way. If you simply ask the JSON parser for the array, the Editor will stuff the results in an Array for you, no extra work needed.
If you need to iterate over the array, you can do so with an iterator loop like so:
If you simply wanted to know if a certain item was in the array (contains), then you could do this trick with Java Lists:
I hope that helps you get where you need to be. ;)
03-13-2020 11:29 AM - edited 03-13-2020 11:53 AM
This is very helpful. Thanks a lot @anthony. I've learned a lot from you with my first UCCX scripting experience.
03-13-2020 11:49 AM
09-29-2020 07:02 AM
This is awesome ! Was looking for a ways to handle string arrays. Found the thread has has everything I needed.
Thank you very much for the neat rick with lists to check if certain value is inside the Array. That reduces several code lines in my code.
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