An array comes in with 2 values, but the number of values in an array can be dynamic (maximum is 4)(Makes more sense in the text below)

Hi all,
I am currently stuck on a problem:

An array comes in and there are 2 values in it. However, via business requirements, an can have up to 4 values. So for example:

Array 1: [“1A”,“2A”]

But since the arrays can be dynamic, they can hold a maximum of 4 values so Array 2 may look something like: [“1A”,“2A”,“3A”].

What is for certain is that there is always going to be 1 value. The problem I am having right is having to loop through it. I would like to go something like this:

If there is a value after the 1st value, store it in a variable. Then it goes on (if there is a value after the 2nd value, store it in a variable). If let’s say there is no value after the 1st one, then mark all those variables as blanks.

I am just a bit lost on how to go about it. I tried it with a datable, and it did not really work out because I cannot set the number of rows to it if I built it. I am trying not to use Excel for this too. Please let me know of any advice, thank you!

Hi @ktanli
VariableArray.xaml (7.5 KB)

Use Array.ElementAtOrDefault(index) method.
Illustrated in the workflow here.

Does it work for JSON arrays as well, so for example:

I would to only assign the “stuff” part of the data to the variable. But the number of the variables depend on the number of values in the “data” portion

With JSON, it works differently.
There are readily solved topics on UiPath forums about this.

  1. Check if your JSON contains a certain key (because you already know the key name)
    How to validate JSON keys before getting value based on key
  2. Get the value
    How to read key_value from the json array - #3 by anmolk171
1 Like