For Loop (Iteration)
Last updated
Last updated
Hi there! In this tutorial we are going to talk about For Loop Connector.
You can use the Easyflow For loop connector to easily create and manipulate lists of data. This connector provides a simple interface for looping through arrays and objects, making it easy to build and transform data. In this video, we will demonstrate how you can unlock the potential of For Loop Connector through two examples: Building a Simple Array. Building an advanced array of object. Letโs get started As first step we are going to create three workflow variable: Var loop for storing the iteration incremental index. Var simple array for the first example. Var complex array for the second example. We will start building our logic by giving initial values to the variables. This can be done using the Variable setter connector. In the key section, pickup the variables using the + icon at the beginning of every variable. Consider 1 variable per line. Regarding the values, it will be 0 for the var loop variables and empty array for each of the other variables. Donโt forget to set this step as a starting point. The next step is the LOOP connector itself. For this example we are going to set the length to 10 iterations. After the LOOP we are going to assign assign values to the initiated variables as follow: Var loop by incrementing it by 1. Var simple array, we are going to add a random integer item to the array by using the โaddโ array and the RANDOM int function expression syntaxes. Var complex array by using the โaddโ array syntax and creating a JSON object with 3 keys: index, uuid and random. Let's map the index key with var LOOP which indicates in which iteration the loop is, uuid and RANDOM int variable syntaxes for the other keys. Then letโs close the loop cycle by linking the last step with the loop step itself. Finally we need to let the workflow display the result. Letโs display the simple array first by using the Mapper connector and map it with var simple array. Letโs now test the outcome by invoking the workflow from the browser. As you can see, the workflow returns an random numbers as expected Letโs Create an additional step to make the workflow return the complex array result. We need an additional mapper and map the complex array variable to it. By testing the result from the browser, we can see that the workflow returns an array of objects, which include the incremental index number as expected.
Thank you for watching this tutorial. Please feel free to contact us if you have any questions.