+ Start a Discussion
Jacky LeeJacky 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 :)




 
Best Answer chosen by Jacky Lee
Jacky LeeJacky Lee
Hey Sebastien,

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_counterIn 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.
LEFT({!var_remaining}, FIND(";", {!var_remaining}) - 1)
    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:
RIGHT({!var_remaining}, LEN({!var_remaining}) - FIND(";", {!var_remaining}))


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:
 User-added image


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

Sébastien RichardSébastien Richard
Hi Jacky,
I have the same issue. Did you find a solution ?
Jacky LeeJacky Lee
Hey Sebastien,

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_counterIn 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.
LEFT({!var_remaining}, FIND(";", {!var_remaining}) - 1)
    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:
RIGHT({!var_remaining}, LEN({!var_remaining}) - FIND(";", {!var_remaining}))


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:
 User-added image


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 :)

 

This was selected as the best answer
ryanschierholzryanschierholz
Thank you for explaining that, Jacky. I had a similar requirement, but your solution inspired mine. I wanted to get a comma separate value (csv) list of email addresses in a long text field, and each one put into a collection, to be emailed. 

A couple things that might be of value to you and the next person:
  • Instead of using a set number to iterate over in psuedo loop, I set a formula (boolean) 'ListEmpty' to check the length of the f_RemainingList list. At the decision node, If it's not empty, the flow would do the assignments as you laid out, and then check to see if the list is empty again.* 
IF(LEN({!varEmailList}) < 5,true,false)
  • Because my list is manually populated on the record, it's rare someone would include a comma at the very end (which is what makes yours work, with semi-colons). Based on this, and my previous implementation, I did run into an 'infinite' loop. So, in order to accomodate for that scenario, my assignment to add the f_currentItem (formula for the current item) to the collection checks to see if there is a comma. if so, it uses your LEFT evaluation; if not, simply returns the variable, assuming it's the last entry. 
IF(CONTAINS({!varEmailList}, ","),
LEFT({!varEmailList}, FIND(",", {!varEmailList}) - 1),
{!varEmailList})
  • 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 
IF(CONTAINS({!varEmailList}, ","),
RIGHT({!varEmailList}, LEN({!varEmailList}) - FIND(",", {!varEmailList})),
"")
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. 
Olivares christineOlivares christine
If you really know how to play the games then your information (https://apkshines.com/)is amazing. Thanks for providing us detail
Olivares christineOlivares christine
You must have good programming laptop (https://techconsumptions.com/best-laptops-for-programming/) for the smooth coding. 
simply buzzes 9simply buzzes 9
Do you know what are the best way to find the best url (https://www.oeyes.com/)that provides an authentic information regarding to the latest sneaker sales, please let me know will be thanskfull for your information.