[Video: How to create looping logic and insert looped variables into documents.]
Looping logic enables end-users to respond to one, or a whole flow of messages, multiple times without you, as a builder, having to create lots of messages to capture all of the occurrences end-users need to input.
It's particularly useful when collecting information where the volume changes from one interaction to another.
For example, in a bot collecting contact details, one user might need to input the details of three people while another user might need to input the details of five.
Looping logic can account for any number of occurrences since there's no limit to how many responses looped messages can receive. These responses can then be inserted into documents in a variety of ways.
- What is looping logic?
- Create looping logic
- Looping in documents
What is looping logic?
Looping logic is a form of bot logic that allows users to circle back and respond to messages multiple times.
- Message #1: Information retrieval
- This retrieves the user's information (e.g. the name of a defendant in a court case).
- Message #2: Looping question
- This asks the user if they want to provide another occurrence of the same information (i.e. another defendant's name) and determines whether the user will loop back to message #1.
- Hint: The most common response type for this message is Single choice - text (i.e. "Yes" and "No"). If the user responds Yes, they would loop back to message #1.
- Message #3: Exit message
- If the user responds "No" to message #2, they will flow onto this message and proceed further along in the bot.
- An example would be if they did not want to provide any further defendant names as first requested in message #1.
Now you know the basics, here's how to create the logic in your bot!
Create looping logic
In either List view or Flowchart, first, create your flow of messages.
- Create the information retrieval message (#1 above).
- This might feature a Text response type, for example.
- Connected to the above, create the looping question (#2).
- This might feature a Single choice - text response type (e.g. "Yes" or "No")
- Following this, create the exit message (#3).
Next, you'll need to connect the messages with the relevant connection rules.
- Connect message #2 to message #1.
- Here's a refresher on how to create message connections.
- Apply the relevant connection rule(s) to ensure that if the user responds "Yes" to message #2 (e.g. "Do you want to the name of another defendant"), the bot will flow back to message #1 to enable the user to input another name.
- Once complete, select the connection between message #2 and message #3.
- Apply the relevant rule(s) to ensure that, if the user has no more information to provide (i.e. they respond "No" to message #2), the bot flows further along the logic.
Hint: When creating the connection rules, be mindful of the rule operations. The appropriate connection rule might not always be "is"/"is not". This will depend on your wider bot logic and you may need to use "contains"/"does not contain" if the user is looping through the bot's flow multiple times.
Looping in documents
Once your looping logic is set up, you can insert the looped variables into your document(s).
Such variables can be inserted either inline within a body of text or as part of a looped block, list or table.
To insert a looped variable,
- Open the relevant document via List view or Flowchart.
- In the Word editor, locate the relevant passage of text, click the relevant location and click Insert variable from the top toolbar.
- Hint: The variable will be the name of message #1 created earlier.
- Done! All details provided by the user will appear inline, separated by a comma and a space (e,g. “Name 1, Name 2, Name 3, Name 4 and Name 5”).
Block, lists & tables
To create a series of blocks, list points or table rows using your looped variable,
- In the Word editor, focus on the block where you want the looped responses to display.
- Click Insert variable as above.
- Select the relevant block, row or list item and click Apply looping from the top toolbar.
- Hint: The block will become highlighted by a pink border, denoting that looping has been applied.
- The contents of the block, row or list will now display as many times as there are responses. For example, if there were five names provided, five separate blocks, list points or table rows will generate.
[GIF: User selecting Apply looping in the Word editor.]
You’re done! Now, test your bot to ensure it works as expected.
- Looped responses can only be inserted in generated documents as laid out above. When inserted in bot messages or notifications, looped variables will only feature the first response.
- Similarly, in the Activity tab, only the user's first response will appear in the interaction record. To view all responses, we recommend inserting the looped variable in a document.
- In documents, we recommend inserting looped responses and applying looping to simple tables, not complex tables or tables within tables.
- When building your bot's looping logic, we recommend creating simple loops. Avoid building logic branches within loops as this is currently unsupported.
- Builders cannot limit the number of loops a user can perform in a given interaction.
Got a question? Contact us at firstname.lastname@example.org.