Expand my Community achievements bar.

SOLVED

More multiple-choice fun: Reading one multi-select and making choices on a second multi-select

Avatar

Level 5

It was supposed to be so easy. And I'm sure it's possible to do this. The particulars are what's irritating. My hope is that I post this and then figure it out tomorrow morning while on my jog.

 

Here's the ask:

A group wants to read a multi-select field on an issue. From that, Fusion would read the choices and map them to another multi-select field.

  • If choice is A, B, or C on first field, it choses 1 on the second.
  • If choice is D on first, field, 2 on the second
  • If choice is E or F on first, 3 on the second

Considering it's multi-select, if the choices were A and E on the first field, Fusion would chose 1 and 3 on the second field. 

I know we're dealing with an array because we're dealing with a multiselect, so I try iterating out all the choices. Then, I set a variable using an IF statement...

...

And I don't know how to aggregate those choices by Issue so I can set the choices on the second field.

I'm almost certain that we have an example of something similar in one of our scenarios but I can't find it.

This has to be easy and has to be a relatively straightforward and common use of Fusion but I'll be dang darned if I could figure it out between meetings. 

 

Any hints would be greatly appreciated and would be credited to you as a free drink if I ever run into you at a Workfront event.

 

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

John

First, I'll cover how I would tackle this, then I'll cover where it's going to get sticky.

Process

  1. Combine all of the multiselect fields into a single array using the merge function, so it looks something like combinedArray=merge({multiselect_1};{multiselect_2};{multiselect_3}
  2. Then, for each of the target properties, I would do updateArray=remove(add({{emptyarray}};if(contains(combinedArray;option_1);property_2_option_1;{{emptystring}}...[repeating for each option]);{{emptystring}}). This will end up with the array you need to update your secondary objects, and repeat for each secondary field/object

Where it's going to get sticky is with a fun quirk of Workfront. If only a single object is checked on a multiselect, it comes in as a simple string, and not an array, but the merge function only works on an array. So what you end up having to do is check to see if the value provided is a string or an array, and if it's an array, then huzzah, nothing further required. If it's a string, then you have to convert it to an array, then pass it into the merge.

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

John

First, I'll cover how I would tackle this, then I'll cover where it's going to get sticky.

Process

  1. Combine all of the multiselect fields into a single array using the merge function, so it looks something like combinedArray=merge({multiselect_1};{multiselect_2};{multiselect_3}
  2. Then, for each of the target properties, I would do updateArray=remove(add({{emptyarray}};if(contains(combinedArray;option_1);property_2_option_1;{{emptystring}}...[repeating for each option]);{{emptystring}}). This will end up with the array you need to update your secondary objects, and repeat for each secondary field/object

Where it's going to get sticky is with a fun quirk of Workfront. If only a single object is checked on a multiselect, it comes in as a simple string, and not an array, but the merge function only works on an array. So what you end up having to do is check to see if the value provided is a string or an array, and if it's an array, then huzzah, nothing further required. If it's a string, then you have to convert it to an array, then pass it into the merge.

Avatar

Level 5

This all makes sense and feels like it should work but it doesn't.

I've done as you suggested and added single-answers into an array of its own and merged it with the multi-select field. I then went to create this array:

JohnJOSullivan_0-1685561156181.png

 

It *should* be pulling more than one option for many of these but it's only pulling one per. And I cannot find where it wouldn't...which doesn't mean there isn't a reason. 

 

Does anything look off with that?

Avatar

Community Advisor

It looks like when you mapped in your 58.combined array, you only mapped the item in the 1st slot of the array. Is that what you intended?

Avatar

Level 5

So when I took that screenshot, it wasn't working. And trying slots was one of those things when it's not working and you try anything--like looking in your sock drawer for your car keys.

 

I did indeed get it working though! When I first looked through your solution, I didn't do every single choice in the multi-select. I tried doing a "contains(field;<partial name of three choices>)." Once I made every single choice on the typeahead, everything worked fine. 

 

Sorry for the delayed response; things are rather nuts, but I wanted to thank you! This taught me so much!

 

Happy impending weekend!

-j 

Avatar

Level 1

Hi @ChrisStephens  

 

I know that this is an old post but I am facing the same issue with my Fusion scenario now. I am able to set variable by using the merge expression to combine the multi select fields. Everything works fine until someone chose a single value on those multi select fields. Are you able to explain further how can we check if the value provided is a string or an array and how to convert them to an array? Is there a way to make sure that the fields are put as arrays no matter if they are filled with multi or single values?

 

Your help is greatly appreciated. Thank you!!