cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3355
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

There are likely multiple ways to do this, but this is how I've done it in one script.

 

Variables
Snag_2a1b1d.png

 

  • Use a Do step and have it read a string variable that is defined as a parameter and split the values into a string array variable.
    strTestNumberArray = strTestNumbers.split(",")
  • Use another Do step to loop trough the array

    {
    int i = 0;

    for (i = 0; i < strTestNumberArray.length; i++)
    if (DNIS == strTestNumberArray[i])
    {
    strTestNumber = DNIS;
    break;
    }
    }

  • Define the values in the string variable that you want in the array on the parameter on the application page as a comma separated string.

    Screen shot from script.
    image.png



Response Signature


Hi Roger,
Thanks a lot for you response. I tried to follow your steps but it's giving me errors no matter if ArrManufactures type String or a StringArray. What am i doing wrong here?
I am actually trying to parse a Jason response and trying to assign the string values to an Array.

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 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.

 

Snag_35df81.png

@Nliya53887 Please update your expression to not have any characters after the last parenthesis to see if that corrects your problem.



Response Signature


Thanks Anthony! yes that semicolon was the issue.

Cool!

Sean Lynch
Level 7
Level 7

...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:

Capture-1.PNG

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):

Capture-2.PNG

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.

Capture-3.png

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

Thanks Sean. Your examples helped me a lot!

 

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.

 

json-array.png

 

If you need to iterate over the array, you can do so with an iterator loop like so:

 

json-array-iterator.png

 

If you simply wanted to know if a certain item was in the array (contains), then you could do this trick with Java Lists:

 

json-array-contains.png

 

I hope that helps you get where you need to be.  ;)

This is very helpful. Thanks a lot @anthony. I've learned a lot from you with my first UCCX scripting experience.

That's great to hear. Good luck with your project.

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. 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: