Hello folks,
As you might already know, recursive functions are used to
perform a particular action a specific number of times. We had explained this in detail in our Tip #2
. Similarly, there is another way in which you can iterate a set of Deluge code 'n' number of times. All you need to do is to create a List and use the For each index task to iterate it for a specific number of times.
Here are a few use cases where this would be useful to you:
To create 'n' number of duplicate records for every newly created record.
To perform a Send Mail task 'n' number of times.
To update old records in bulk.
In the below-given sample script, we are implementing the logic on a custom function and any workflow in your Zoho Creator application can trigger this function.
Let's consider the 'number' (int number) provided as input for the above function is 10. As a result, the function would return the below list.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- list listintgenerator(int number)
- {
- //We'll need to create a reference List for indexing purpose
- indx = number - 1;
- str1 = " ";
- val = leftpad(str1,indx);
- lst_val = val.replaceAll(" ","0,").toList();
- lst_temp = List:Int();
- counter = 1;
- //Iterate each index of the above generated List and perform counter operation
- for each index x in lst_val
- {
- lst_temp.add(counter);
- counter = counter + 1;
- }
- return lst_temp;
- }
Now, the generated List can be iterated using a For each task, and within that loop, you can add the set of Deluge code that has to be executed 10 times.
Hope this tip would be useful to many of you. Keep watching this space for more such tips.