In this tutorial, you will learn how to convert a list of comma-separated values into individual text items. This process is especially useful when you have saved answers from a Multiple Select input node in a database and wish to reuse them as default values for another Multiple Select input in a different module. Follow along to discover the steps for implementing this solution.
📚 Transform a List of Comma Separated Values Into Text Values To Use Them as a Default Value in Multiple Select Input Nodes
In this article, we assume that you read a comma-separated list of text values from a database General DB (in practice you will use your own database here) via a Read From a Database action. We assume that this list contains end users answers from a Multiple Select input node that have been saved to General DB earlier on in the process.
Our aim is to split the comma-separated list into individual text items and use those text items as default answers in a Multiple Select input node.
Rebuild example
- Create a data view by selecting the database (in our example, we call it General DB) where the comma-separated list is saved. Add an Action to start the module you will be building below. Create a new parameter and change the Key to record_id. See for a detailed explanation here.
- In the module in which you want to use the comma-separated list to get the default values, add a URL Parameter action and type record_id into the QUERY PARAMETER NAME field. Add this action on top of the Multiple Select input for which you want to use the values from the comma-separated list as default values.
- Add a Read From a Database action and name it Database Read. Connect it to the database in which the comma separated value has been saved (in our example, we call this database General DB). Reference the URL parameter in the ID field.
Now, proceed with the first step of the actual tutorial.
Tutorial
Here is how to proceed:
- First, determine the items and the maximum number of items you anticipate in the Multiple Select input question. As an example, if we build a Multiple Select input like the one in the image below, we anticipate to have a maximum number of items of 4.
- Implement the following logic directly above the Multiple Select input node for which the comma-separated list should determine the default values:
- Create a Text Block value for each option in the Multiple Select input. In each of these Value nodes, write the name of the corresponding answer option from the Multiple Select input separately.
- Insert an Empty action node above the first and below the last Text Block value. Also, insert an Empty action between each Text Block value.
- Create transitions that lead from one Empty action to the next, skipping the Text Block value in between.
- For each transition leading from the Empty action to the Text Block value, configure a condition using the Rule Builder. In the variable field, select the variable containing the comma-separated list from the Read From a Database action (in our example, this variable is called Database Read → CounterPartyCountry). Then, set the operator as Contains and type the answer option defined in the following Text Block value in the value field.
- Leave the condition in the other transition as else. This way, end users will skip the node if that answer option was not present in the comma-separated list.
- In the Multiple Select input node's default value section, reference the Text Block value.
- Create a Text Block value for each option in the Multiple Select input. In each of these Value nodes, write the name of the corresponding answer option from the Multiple Select input separately.
Have a look at the expected result below: