cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4012
Views
80
Helpful
19
Replies

UCCX handling Arrays

Nliya53887
Level 1
Level 1

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

19 Replies 19

Anthony Holloway
Cisco Employee
Cisco Employee
Quick note here, in Java, and some other languages, the size of an Array is fixed, and in some cases you need to dimension the array before using it. There is an exception however, and it's when you use the String.split method which will dynamically set your array size and fill it with values at the same time (my preferred method).

So, if you have a String Array which starts out as null, then you cannot assign the first index of my_array[0], because the array has no size.

Hello,

Two questions here.

1. I am confused why the script is not getting the value of iArrayElement and throwing the following error in the get JSON document data step. When debugging it shows the value as 0.  If I hard code a number then it works fine and returns the string that I am expecting. 

Exception : nested exception is: \n\tcom.jayway.jsonpath.InvalidPathException: Could not parse token starting at position 40. Expected ?, ', 0-9, * "

 

Capture2.JPG

2. @Anthony Holloway like you have mentioned I got the invalid null array error when try to set a sting to ArrManufactures. (I got to this step only when i had hard code the array element as mentioned in the first question) What is the best approach to parse the this JSON response. I was trying to loop through the response, get one value at a time and build the array.

[
"SHORETEL",
"UNSPECIFIE",
"AVAYA",
"CISCO",
"SHORETEL"
]

Just in case you didn't see it, I replied to this on a different reply you made. I'm guessing you moved it?

I had the exact issue recently. I wanted to store a list of card numbers in a string array, which will be return as the response to a REST call. There's no way to know the number of cards belonging to a customer, to initialize the array prior. So I had to declare an array prior with a larger size. 

 

1. debug show string as following, while executing. 

JSON_2.PNG

 

2. However, I could see after get JSON document details step filling the data into array, it also gets resized into actual element count. 

JSON1.PNG

 

JAson 3.PNG

 

3. After going though your post, I assumed may be JSON data step has the same behavior as string.split. Then I removed array initialization step and kept array size undefined. During the execution, I could see array get's data accordingly. 

 

JSON 4.PNG

 

JAson 3.PNG

 

I'm not sure how safe to use this in production environment, specially we have seen some garbage values exist when string arrays not defined properly or accessed improperly. I like to keep it this way, since it's much cleaner. 

Thank you !

Awesome info, and thank you for sharing!