Iterate Tasks
The Iterate Tasks
action empowers you to efficiently repeat actions based on specific data or inputs. Common development tasks often require repetition under certain conditions. To streamline this process, DronaHQ introduces the Iterate Task
Action. With the Iterate task, you can group tasks together to be executed iteratively under defined conditions.
Setting up the Iterate Tasks Action
Access the Actions section of any control.
Search for
Iterate
in theOn-Screen Actions
section under theUtility
group.Choose a control or keyword from the dropdown list, containing all currently used controls and keywords in your app. The iteration will operate on select controls and keywords such as datastore, multi-select, and others that return responses in list format.
Iterate Tasks supports the following items for iteration:
- Static Count/Number
- Array
- Variable
- Controls
Click
Finish
to add the Iterate task for the selected control.NOTEYou can perform up to 100 iterations only.
Configuring Task Iteration
After setting up the iteration loop for desired controls or keywords, proceed to configure actions or tasks under the loop to be iterated. You can add tasks, server-side actions, and even nest iterations between
ITERATE TASKS START
andITERATE TASKS END
.Let's assume you're using a datastore control containing an object with multiple keys and values.
Data in Datastore:
Set up an iterate task by selecting the datastore in the action of a button.
Between the task start and end, add desired tasks under on-screen actions and server-side actions that you want to iterate. For instance, use the
Toast
action underDialogs
in on-screen actions.Select keywords from the datastore selected in the loop for the toast. These keywords serve as parameters for the required number of iterations.
The toast will display data as many times as the title and message data are available in the datastore.
You can select any attribute of the object exclusively using keywords. Two default Iterate Task keywords are available:
<Iterate Task Name>.INDEX
: Provides the index of the item from the data, ranging from 0 to length-1 of the data. The number of iterations and iterated data are determined by selecting their index.<Iterate Task Name>.VALUE
: Provides the whole object/string of that index if you're iterating over an array of objects.
Click
Continue
and thenFinish
.
Iteration in Server-Side Actions
You can include server-side action tasks in iterate tasks, but it requires a variable to store data from the server. Due to differences in request times, the order of received data might not be in sequence. To ensure sequential correctness, custom JavaScript code can be used.
Nested Iteration
For cases involving multi-dimensional arrays of objects, where iteration is required within each object, you can nest iterations with distinctive actions and tasks.
Putting Iteration into Action
With the click of a button, the iterative toast action takes place. The number of iterations matches the number of indexes and values available in the datastore.
When binding a list-type (array of JSON objects) keyword, accessing Keyword.KeyName
in any other task within the iterate scope will provide that index's specific key value, rather than the entire array value.
In the image above, choosing a specific key like name or email will iterate through that particular key-value only.