Variables

In this video, we will walk through everything you need to know about Variables in Easyflow.

  • Let’s first create a new flow with the title "Variables".

  • To begin this exercise, we will drag the Google Analytics connector into the canvas and configure it.

  • We will fix the Start date and End date values first, before making them dynamic by mapping them to variables.

  • Remember to set the Google Analytics connector as initial starting points.

  • Click Preview Results to test the outcome. The data is returned in JSON format, and in total 824 records are returned based on the configured date criteria.

The next step is to give users the capability to specify the Start Date and End Date every time they run the workflow.

This means we need to modify the Google Analytics steps to make the "Start and End dates" dynamic based on the user's input.

This can be accomplished by creating Start Event Variables.

To create a Start Event variable, you can either click on the "Variables" menu from the toolbar, or from the dynamic content panel by pressing the icon located on the right side of the "Variables" group.

  • From the Variables window, select the Start Event and create 2 variables. Name the first variable var_start_date and name the second variable var_end_date.

  • Then, from the Google Analytics configuration panel, map these 2 variables to "Start Date" and "End Date" text boxes respectively, and press "Apply" to save your changes.

  • To run the flow, click the Run icon from the toolbar. The "Start Event" variables appear in the "Run Input" with empty values. Try running the workflow without giving any value for these variables to see what will happen.

  • As we can see, the workflow returns an error message produced by the "Google Analytics" step stating that the input parameters are invalid.

  • Let's run the workflow again, but this time we will give values to the "start and end dates". We see that a successful response has been returned and the data are correct as expected.

  • In addition, we can run the workflow from the browser or from Postman by using a similar method to calling any API.

  • When you click on the information icon in the toolbar, you can view the Endpoint URL for your workflow. At the end of the URL, you can also see the "Start Event" variables that are passed in as parameters.

  • By setting the values for these parameters and calling the full URL from the browser, the workflow will be executed and pass the values to the Google Analytics step.

  • Also, we can call the same URL from Postman by using the GET method.

Next, let’s talk about another variable or type Workflow.

The Workflow variable is an internal variable that can be used for various purposes within a workflow.

Unlike the “Start Event” variables, the “Workflow” variable doesn’t accept input from the user.

We need to use the Variable Setter connector to set and update the value of a "Workflow" type variable. This will allow us to use this type of variable to support the logic within the workflow.

  • For example, let’s create three “Workflow” variables var_full_name, var_first_name and var_last_name. Then use a Mapper connector to create a JSON object and map its values to the newly created workflow variables and set this connector as a starting point.

  • When running the workflow, we will notice that these variables have null values as expected.

  • Next, we will use the Variable Setter connector to set initial values for these "workflow" variables.

The "Variable Setter" connector requires two inputs: the Key and the Values.

In our first experiment, we will set an initial value for the var_full_name variable and leave the rest blank.

  • In the Key text box, map the "var_full_name" variable by pressing the "+" sign located at its left side. The variable should appear in black inside the "Key" text box.

  • For the "Values" text box, type "Peter Easyflow".

  • Save and preview the results. As we can see, the "Full name" key has a value while the "First name" and "Last name" keys are still null.

Next, let’s configure the Variable Setter connector by giving values to all the 3 variables.

Each variable should appear in black color and on a separate line.

  • Enter the desired values for each variable in the "Values" text box, one per line. The first line value will represent the value set for “var_full_name”, the second line for “var_first_name” and the third line for “var_last_name” variables.

  • Press Save and preview the results. As we can see, all JSON-formatted data keys have the expected values.

Assuming that the "Full Name" field consists of a combination of the "First Name" and "Last Name" fields, let's take a look at how we can configure it.

  • In the "JSON builder" second step, map the "var_first_name" and "var_last_name" together inside the "Full name" key value. You can leave a space between the two mapped variables.

  • Save and preview the results. As expected, the "Full name" field has its value mapped with the "var_first_name" and "var_last_name" variables instead of the "var_full_name" variable.

  • Let's see how we can do that using the Variable Setter connector. We need to drag and configure an additional "variable setter" connector between the initial and the last steps.

  • This new Variable setter connector will be used to set a value for the "var_full_name" variable, which is a combination of the "first name" and "last name" variables.

  • Next, we'll need to remap the "full name" key in the "JSON builder" step with its variable

  • Remember to link your steps and save your changes before previewing the results.

  • As you can see, all the keys are reading from the variables and returning the expected results.

In the next case, we will show how workflow variables can persist their values between runs, and the benefits this provides.

Suppose we want to count the number of times the workflow is executed. To do this, we will use a variable that starts with 0 as its initial value and increments by 1 every time the workflow is executed.

  • In the last "JSON Builder" step, we will add an additional key named numberOfRuns.

  • Next, we will create a new variable of type "workflow." We will name it var_number_of_runs with 0 as its default value.

  • Also, we have to map this new variable with the numberOfRuns key then save and preview the results.

  • As we can see, the numberOfRuns key is appearing in the results with a value equals 0. By trying to run the workflow multiple times, we notice that the "number of runs" value is not incrementing.

We will use one of the Variable setters in the upper steps to configure the incrementation logic of this variable.

  • From the Variable Setter step, map the var_number_of_runs variable to the "key" textbox by clicking on the "4 dots" icon. Then locate the variable and click on its "Plus" sign. The "var_index" variable should be added to the text box in black. Remember to configure each variable in a separate line if you have multiple variables in the "Variable Setter" connector.

  • From the "Values" text box, click on the "4 dots" and select the "var_number_of_runs" variable. Then, click on the "Plus" sign and type So the syntax expression will be "var_index" plus 1.

  • Save your changes and then preview the results. As you can see, the numberOfRuns gets incremented every time we run the workflow.

  • Let's show you an additional interesting example. We will create a new variable of type workflow named var_stats.

  • In the variable setter let set its value to empty JSON curly brackets, then map it to the last "JSON builder" step by creating a key named stats.

  • When previewing the results, you will notice that the key is added to the JSON object as expected.

Next, we will map the "stats" retrieved from Google Analytics to the "stats" variable instead of setting it as an empty JSON value.

  • To accomplish that, we will place the "Google Analytics" at the beginning and set it as a starting point. Then, we will link it to the first variable setter step.

  • To make the example easier, we will give fixed values to the "Start date" and the "End date" of the "Google Analytics" step.

  • Finally, we need to map the var_stats variable with the stat data coming from “Google Analytics” connectors.

  • By previewing the results, we can see that our built JSON object returned the stats from “Google Analytics” as expected.

Thank you for watching this video.

Please feel free to contact us if you have any questions.

Last updated