Creating and using Variables

Studio provides the Variable feature which can be used to create variables that are of type persistent and non-persistent in nature. You can then use the variables and bind them to controls or use them for creating rules and in formulas.

Adding variables

Let us consider a form for adding a request for Leave application. We would have a login screen. The values entered using the controls here would then be stored in variables for the user name and password and then use these values across multiple screens as well as multiple MicroApp launches.

  • To add a new variable, under Studio Console click Variables, and click +Add.
  • Now add the variable Name1 and Name2 and select type as Persistent or Non-Persistent.
    • The Persistent variables are those which retain their values across multiple Microapp launches. So if you exit any MicroApp and reopen it later, the persistent variables would get the last saved value. For example, you can add variables to maintain the login id and password values across screens, its value would not be reset, they would get the last saved values.
    • The Non-persistent variables would be those that would not retain state across MicroApp launches. Hence they cannot be used for scenarios where you want to restart your MicroApp multiple times. However, the non-persistent variables would not lose their values in multiscreen scenarios. So we are using both types for the sake of this example.
  • You can assign a Default value to the variable which would be used in case no value is provided.

Using variables

Now in this example, we are using a login screen that has the username and password input controls. These would be the values that would be assigned to the variables and used for the remaining screens. We would be navigating to the next screen for a Leave request. You would be setting the values for the text controls for the username and password to the two variables Name1 and Name2. They would now be used in the Leave application (second ) form.

To set the values to the variables we would have to add an action. We would be setting the variables using the SETVARIABLE formula. Now this formula is available in the Action of the click event for the Action button added to the first form. Let us now assign the values and also navigate to the leave application screen.

In the second form, you need to simply assign the variable to the control. So for the User name text control let us Bind Data > Variables and select variable as “Name1”. Click to Save. You would be able to use the value of the variable that was assigned on the Login form earlier. So when you run the form you can view the entered value or the default value in case no value is entered. You can use the variables in your custom formulas as well in a similar manner.

Using variables in Rules

Now that we have seen how to add variables, you can also use them when creating Rules. Now for your current Form for Leave application let us add a Rule that Casual leave can be of one day only if the Username is “Drona2”.

To add a rule, under the Studio console click Rules. Now click Add Rule. You can see the variable under SelectFields. You can use the variable as required to specify the condition and click Save.

Thus note that the variables that you create are available within Rules as well. However, you cannot get them in Validations as we are using the Controls in creating the validations.

It is important to remember that when you change the value of the variable, it will be reflected in all the places like formulas, rules and controls wherever it is used.