Step operations
Last updated
Last updated
In this video, we will walk through everything you need to know about Step operations in Easyflow.
In this example, we will show how to add JSON data from the first step into an array. As a result, we are looking to have an array of JSON data.
Next, add another Mapper connector and link it to the first step. We will give it a title of "Add JSON into Array."
From the right side of the "Mapping Items" text box, click on the "4 dots" to open the Dynamic content panel.
To add the JSON into an array, we can use the "Add" Array function expression.
This can be done by clicking on the Array tab and then selecting Add.
The Add array function requires two input parameters: The "Source array" and the "Value" which will be the JSON object we've built in the first step.
For the "source array", we will type two box brackets representing an empty array of JSON.
For the "value" we will pick the "Build Json Object" item from the first tab in the Dynamic content panel.
The final syntax for the "Add JSON into Array" step will be:: “Add (Empty Array, Build JSON Object from step 1)
Remember to save your configuration before previewing the results. As you can see, the flow returns an array of objects in JSON format.
In the next example, we will extend the case and create an array with 10 JSON objects. To do this, we will use:
The Loop connector to iterate 10 times, and during each iteration, it will append a single JSON object to the array.
A Variable to be used to store the array values during the iteration.
Another Variable to use as an index while iterating.
A Variable Setter connector to be used for updating and giving initial values to the created variables.
Let's create two variables of type "Workflow." We will name them "var list people" and "var loop"
In the Variable Setter connector, we will set initial values for each of these two variables:
The "Var list people" will have an empty array as its initial value.
The "Var loop" will have 0 as its initial value.
We will also give the Variable Setter connector a title of "Variable - Initiate" and connect it to the second step and to the loop step, respectively.
With regards to the Loop connector, we will configure the "Index Length" by giving it a value of 10. This means that the loop will iterate 10 times.
Finally, we need an additional variable setter to be placed after the "Loop" step. This connector will be responsible for appending the JSON objects to the "var list people" and incrementing the "var loop" index by 1 during each iteration.
To append a JSON object to the "var list people" variable, we will use the "Add array" function expression. This is the same procedure we used during the second step in the video. We will give the "add" function these values:
Map the source value to the "var list people" variable.
Map the value to a custom JSON-formatted object. The JSON object will have “First Name”, “index”, “country” and “City” keys.
Consider mapping the "First Name" to a predefined UUID string variable and the index to the "var loop" variable. This will help distinguish between the JSON object items that will be inserted into the array later on.
Remember to close the Loop cycle by linking the "Variable Setter" last step back to the "Loop" step, then press Save.
Lastly, we will configure and place a Mapper connector as the final step to show the output. The "mapper" should be mapped with the "Var list people" variables, in which we have already built the array of JSON.
After previewing the results, we can see that the output was returned as an array of JSON objects. The "first name" key contains the UUID and the index contains an incremental number, as expected.