You need to sign in to do that
Don't have an account?
Jacky Lee
Populating a collection variable from a long-text field
Hi,
Within a visual flow, I'm wondering if I can populate a collection variable using semi-colon separated values (;) in a single input text box. For the use case, I'd like to append an ad-hoc Taskray Checklist to a Taskray Task using only the flow interface, but as the items are ad-hoc, I can't use a template for it.
For example, if I input this in ONE long text field:
Apples;
Bananas;
Carrots;
Can I pass it into a collection variable using a loop so it is [Apples, Bananas, Carrots]?
I have simulated this by using LEFT({!Checklist}, FIND(";", {!Checklist}) - 1) to get the first row and adding it to the collection variable, trimming it from {!Checklist} and doing it again for the second row, etc. This creates the collection var as long as I stick to the number of assignments I've used.
But the problem is I can't figure out how to build it into a loop to handle variable number of items. Is there any way to do this using only flow tools?
Thanks in advance :)
Within a visual flow, I'm wondering if I can populate a collection variable using semi-colon separated values (;) in a single input text box. For the use case, I'd like to append an ad-hoc Taskray Checklist to a Taskray Task using only the flow interface, but as the items are ad-hoc, I can't use a template for it.
For example, if I input this in ONE long text field:
Apples;
Bananas;
Carrots;
Can I pass it into a collection variable using a loop so it is [Apples, Bananas, Carrots]?
I have simulated this by using LEFT({!Checklist}, FIND(";", {!Checklist}) - 1) to get the first row and adding it to the collection variable, trimming it from {!Checklist} and doing it again for the second row, etc. This creates the collection var as long as I stick to the number of assignments I've used.
But the problem is I can't figure out how to build it into a loop to handle variable number of items. Is there any way to do this using only flow tools?
Thanks in advance :)
I actually did end up figuring it out, although it is a bit of a lengthy process. The idea is to loop through your input "list" variable, where each loop you isolate one item and add it to a collection variable, then trimming that item from the input variable so that the next loop will return the second item, and so on.
It's a very roundabout way of simulating a for/while loop that could get the job done in a few lines of code.
Steps:
1. Create a long text input field (var_items) where you enter the list as above on a screen, separated by ( ; ).
2. Create a regular collection variable of type Number (coll_counter). In an Assignment, add to the collection: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9... Or whatever max length you want the list to be. This is so we can artificially loop through var_items x number of times.
3. Also assign a variable (var_remaining) to hold the full var_items text.
4. Set up a Loop which loops through coll_counter. In the case, it will loop 10 times.
5. Here's the tricky bit. In every iteration of the loop, it will do 3 things in a single Assignment step:
5.1. Create a variable to hold the current item in the list (var_temp). Set it to equal a formula (form_temp) that isolates all text before the first semi-colon. 5.2. Append (Add) to another collection variable (coll_items) whatever is in var_temp. This is the final collection you can use elsewhere.
5.3. Edit the remaining text to remove that item you just pulled out. So when it loops again, step 5.1 pulls out item 2, then item 3, etc...
You can do this by assigning var_remaining to a formula that cuts the first item off:
Now you are left with coll_items, which is a collection of all the items you just input (without semicolons).
Here's a picture of the flow's items:
I have no idea if this is the easiest way or most concise way, but it has worked for me so far. There is only one minor issue: If you enter the items on separate lines, the collection will store the linebreaks at the front of each item. So when you actually use the collection, it might display weirdly. I have tried stuff like substituting the carriage return with nothing, but it's not too big a deal.
If you want pics of the steps, or have any recommendations please let me know :)
All Answers
I have the same issue. Did you find a solution ?
I actually did end up figuring it out, although it is a bit of a lengthy process. The idea is to loop through your input "list" variable, where each loop you isolate one item and add it to a collection variable, then trimming that item from the input variable so that the next loop will return the second item, and so on.
It's a very roundabout way of simulating a for/while loop that could get the job done in a few lines of code.
Steps:
1. Create a long text input field (var_items) where you enter the list as above on a screen, separated by ( ; ).
2. Create a regular collection variable of type Number (coll_counter). In an Assignment, add to the collection: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9... Or whatever max length you want the list to be. This is so we can artificially loop through var_items x number of times.
3. Also assign a variable (var_remaining) to hold the full var_items text.
4. Set up a Loop which loops through coll_counter. In the case, it will loop 10 times.
5. Here's the tricky bit. In every iteration of the loop, it will do 3 things in a single Assignment step:
5.1. Create a variable to hold the current item in the list (var_temp). Set it to equal a formula (form_temp) that isolates all text before the first semi-colon. 5.2. Append (Add) to another collection variable (coll_items) whatever is in var_temp. This is the final collection you can use elsewhere.
5.3. Edit the remaining text to remove that item you just pulled out. So when it loops again, step 5.1 pulls out item 2, then item 3, etc...
You can do this by assigning var_remaining to a formula that cuts the first item off:
Now you are left with coll_items, which is a collection of all the items you just input (without semicolons).
Here's a picture of the flow's items:
I have no idea if this is the easiest way or most concise way, but it has worked for me so far. There is only one minor issue: If you enter the items on separate lines, the collection will store the linebreaks at the front of each item. So when you actually use the collection, it might display weirdly. I have tried stuff like substituting the carriage return with nothing, but it's not too big a deal.
If you want pics of the steps, or have any recommendations please let me know :)
A couple things that might be of value to you and the next person:
- Similarly, in order to remove the last item, the remove assignment has to account for whether there is a comma or not. If not, it removes the last item, so my f_RemainingList formula is
I tested with a line break and mine handles it ok (YES!), but I understand that our scenarios are different.*Mine is built in Lightning Flow; perhaps this wasn't an option in the older version.