Combine a list into a single text

In Triggre, you can use either a single Data item or a List of Data items to perform operations with. When using a List, in some cases you want to use a single value from each of the Data items in the List and combine them into a single text value.

In this article we will show you how this can easily be done using a Repeat action in a Flow Part. As an example we will use a List of Relations to build a single text of all first names of those Relations.
Relation list overview

Setup

  1. Create a Data Item for storing the temporary value, e.g. Temp combine all first names.

  2. Create a Property within the Data Item for the storage of the actual value, e.g. Combined first names.
    Given the examples, the result should look like this:
    Temp combine all first names Data item

  3. Create a new Flow part and then rename it to Combine Relation first names in text:

Designing the Flow Part

  1. Use the add data action to create a Temp combine all first names Data Item. Leave the value of the Combined first names Property empty.

  2. Add a Lookup action to the Flow Part to create the List of Relations .
    In this example we will leave the selection empty to select all Relations.
    Add step

  3. Add a Repeat action after the Lookup for the List of Relations.

  4. Open the Repeat action and add a Caculation action to add the value of the current Relation to the value of the Temp combine all first names.

  5. After the Calculation action, add an Update action to save the newly calculated value into the Combined first names attribute in the Temp combine all first names Data item to replace the old value.




    Value selection

  6. After completing the action, finalize the Repeat action by connecting the Update action to the end of the flow, by choosing End the repeat action.
    The flow in your Repeat action should now look like this:

  7. Close the Repeat flow by clicking the Arrow in the left top side corner of the screen…
    We now have added the first name from each Relation to the text value in the Temp combine all first names Data item. However, we have also added a separating character (the comma) for each item to the text, including the first Data item that was processed. For this first Data item, no separator value is necessary, so we should remove that from the string value in the Temp combine all first names Data item.

  8. After the Repeat action, add a new action of the Calculation type and use the Function CUT A FROM B TO END to keep everything but the first separator in the text value.
    Since we have used only one character (a comma) as a separator, we start cutting the text value from position 2.


    We now have the final text value and as a last step we replace the value in the Temp combine all first names Data item with this newly calculated value.

  9. Add an Edit data action to your Flow Part to update the Temp combine all first names Data item.

After the previous steps, your Flow Part should look like this:

You are now ready to use it in your application.
When using this Flow Part, always make sure to clear the entire Temp combine all first names Data item before the Flow Part is executed. That way you make sure to start with a clean List every time.

Tip 1

In this example we have used a comma to separate each first name. This can be replaced by any other separating value, such as only a comma and a space, a semi-colon (β€œ;”), a slash (β€œ/” or β€œ\”), etcetera, depending on the goal you have with the single text value.

Tip 2

In this example we have combined the selection of the List and the Repeat action in a single Flow Part. Since the selection criteria may vary in your application, you may want to add the List as an Input parameter to your Flow Part and do the actual selection elsewhere, such as in a User Flow. In that case the Lookup action for Relations can be removed from the Flow Part and in the Repeat action the reference to the Lookup result is replaced by a reference to the import parameter Relations List.

2 Likes