How to Iterate On Variable Number of Data
Updated
In IVR systems, a loop node is a powerful node that allows for efficient and dynamic handling of list or array variables. When dealing with collections of data, such as a list of accounts or transactions, the loop node enables the system to iterate through each element of the array, performing specific actions or operations on each item in a systematic manner.
By utilizing a loop node, IVR systems can automate repetitive tasks and provide personalized interactions with callers. The loop node acts as a control structure, enabling the IVR system to efficiently traverse through the elements of the array, executing pre-defined actions or sequences of operations for each item. For instance, in the context of a banking IVR, the loop node can be utilized to provide callers with a summary of their account balances, transaction history, or other account-related information.
Pre-requisite for configuring this node in IVR:
Sprinklr Voice should be enabled for the environment and your user should have IVR View, Edit or Create permission.
In order to Loop node in between the IVR , In the IVR Builder, click the New icon on the path where you want to add Loop and select the Add Loop node under system nodes.
Here is the sample configuration for Add Loop node-
Components-
Major components are-
Collection Variable: This is where you provide the name of the variable that holds the list or array. The loop node will iterate through each item in the list.
Loop Direction: You can choose the direction in which the items in the list will be processed. For example, if you select "First to last," the iteration will start from the first element of the array.
Loop Variable name: In this you need to define the name of the variable that will hold the value of the current element during each iteration. This variable will be used inside loop to take action on each item in the list.
Loop node will have two paths, it will look like this on the canvas-
In the "Each Item" path, you can add any nodes like "Operator Says", "API Node", etc to perform actions on each element of the list. The value of the current iterated element is stored in the variable specified in the "Loop Variable Name." Once you finish performing actions on an element, you can add it back to the loop node.
After all the elements have been processed, the IVR system will move forward with the "After Last Item" path.
Resources related to loop node-
Loop Variable name- In each iteration this variable will hold the value of the current element on which iteration is happening. This variable will be used inside loop to take action on each item in the list.
Index- The index represents the current count or position of the iteration. It helps you keep track of where you are in the loop. For instance, if you are processing the third element of the list, the index will be 3.
Note: Index starts from 1.
If Loop Variable name is current then you can access current and current index inside the loop using resource menu.
How to Break Loop in between?
In certain situations, while iterating through a list using the Loop node, there may be a need to prematurely end the loop for specific conditions before reaching the end of the list. To accomplish this, the IVR system provides a node called the "Break Loop" node.
When you add the Break Loop node to the "Each Item" path of the Loop node and connect it back to the Loop node, it enables you to stop the iteration at a particular element of the list. Once the Break Loop node is triggered, the IVR immediately exits the loop and proceeds to the "After Last Item" leg. This functionality is particularly useful when you encounter a condition or requirement that warrants stopping the iteration process prematurely.
You can add break node in similar way inside the loop. i.e.,
In order to add Break node in between the loop , In the IVR Builder, click the New icon on the path where you want to add Loop and select the Add Break node under system nodes.
Note: You must add break node inside the loop node only.
Here is the sample configuration for Loop with Break node-
In the example given above, the loop will break when the decision for break loop will satisfy and the flow will move to After last Item.
Note: Always use decision box or some condition before adding break node.