cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

IRPA - count unique values in array

liskaj01
Participant
0 Likes
302

Hi, I am using activity get values (cells). This gives list of values. Using this variable and embedding it with ".length" it gives number of values. But how to count unique values? IRPA suggest things like ".count" or ".unique" but it gives empty result. I have also tried to use custom script like this one:

const arr = RunID;
function countUniqueArray(arr) {
const Result = [];
arr.forEach(item => {
if (!Result.includes(item)) {
Result.push(item);
}
});
return Result.length;
}

return(countUniqueArray(arr));

But issue is:

1) when RunID (returned values from excel) are passed directly, counting of unique values does not work and gives only total number of items correctly, but not unique values

2) when insted of RunID I hard code something like ["apple", "banana", "apple", "orange"] it works correctly and returns 3

So either change input to something like in 2) (but how) or use some javascript function directly in one of the steps.

Many thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

liskaj01
Participant
0 Likes

ah, just found that devil in the detail - output has to be set in format like below:

liskaj01_0-1747390233611.png

Then it works in the script above. However I am still curious if this can be made easier? for stepX.returnedValues I see also function like "CountUniqueArray" however it also gives no result like {}