Expand my Community achievements bar.

The Community Advisors application is now OPEN for the second class of 2024. Apply to become a part of this exclusive program!
SOLVED

How to check if a parameter value is an arrray?

Avatar

Level 4

Hi, 

In a Fusion Tools Module I'm trying to set a variable with the first item selected in a multi-select dropdown. However, if only one item is selected, Workfront returns the value as a string rather than an array with one value. This is quite frustrating, but I thought I'd just check to see if the value is an array or not, but there don't seem to be any functions to do this.  I've tried length, but that just returns the number of characters if a string is returned.

Does anyone have any advice?

Rob

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can do something like this

 

if(length(get({variable};1))>1,array,string)

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

You can do something like this

 

if(length(get({variable};1))>1,array,string)

Avatar

Level 4

@ChrisStephens 

Sorry, I missed your reply. Thank you. I hadn't seen the GET function, this is useful. 

I know this is a different question slightly... but is there such a function like isArray()? to tell whether the value returned from a multiselect is an array or not?

 

Currently I use join() using an obscure separator, then I check for the existence of the separator. That's all I could think of.

Avatar

Level 1

Hello -

I've also run into your problem:  multi-select field values are returned as an array if more than 1 item is selected, but as a text string if only 1 item is selected.  In my case, I want the field value to always be an array, but Fusion offers no way to check if the the field value is a string or an array.

So what I did was:

(a) convert the field value to a string

(b) check if that string begins with the left-bracket character "[" which indicates that the field value is an array and therefore is already in the array format I want

(c) Otherwise, the field value must be a string, in which case I convert that string to an array by splitting it by a delimiter character such as vertical pipe that the string does not have, forcing the string into an array of 1 element.

Putting this all together, the formula is as follows, which will ensure that the field value is always returned as an array:

if(contains(toString(FIELD_HERE; "[") ; FIELD_HERE; split(FIELD_HERE; "|")))

I hope that helps.