Configuring Variables

Discover how to configure variables in your application with our comprehensive guide. Optimize your data and improve your code's performance!

Configuring variables is an essential step to customize and optimize your application. Variables allow you to store data and reuse it in different parts of your program. In this article, we detail the steps to add and configure variables, as well as the best practices to follow for effective use.

Step 1: Access the Variables Section

To begin, access your application's configuration view and navigate to the Variables section. There, you will find a list or table displaying all the existing variables in your application.

Step 2: Add a New Variable

To add a variable, click on the Add button located at the top right of the variables table.

Step 3: Name the Variable Optimally

In the add form, start by naming your variable in the Variable Name field. A clear and descriptive name facilitates maintenance and reuse of the variable in your application.

Variable Naming Rules:

  1. Avoid spaces and special characters: Use underscores (_) to separate words if necessary.
  2. Numbers are allowed but not as the first character: For example, variable1 is valid, but not 1variable.
  3. Do not use reserved names: Avoid protected names such as NOW or TIME.
  4. Ensure unique names: Each variable must have a unique name, different from other variables and flow properties.

Naming Example:

To convert a temperature from Celsius to Fahrenheit, you can name the variable temperature_fahrenheit.

Step 4: Configure the Variable Expression

After naming the variable, define its expression. The expression determines the value of the variable and can be:

  • A constant: A fixed number or a string of characters.
  • A boolean expression: Returns true or false.
  • A mathematical expression: Uses arithmetic operators to calculate a value.
  • A conditional expression: Uses ternary operators to implement conditions.

Using Existing Variables in the Expression

To reference other variables or flow properties in your expression, use the $ symbol. A dropdown list will appear, allowing you to select the desired variable.

Expression Example:

To convert a temperature in Celsius (variable $temperature_celsius) to Fahrenheit:

($temperature_celsius * 9/5) + 32

Step 5: Use Ternary Operators for Conditions (Optional)

Ternary operators allow you to introduce conditions into your expressions. They are useful for creating variables whose value depends on certain conditions.

General Syntax:

condition ? value_if_true : value_if_false

Usage Example:

To define a variable is_hot that is true if the temperature is above 25°C:

$temperature_celsius > 25 ? true : false

To learn more, consult our article on using ternary operators.

Step 6: Add Units to the Variable (Optional)

In the Units field, you can specify the unit of measurement of your variable. This is particularly useful for numerical values representing physical measurements.

Example:

For the variable temperature_fahrenheit, you can indicate °F as the unit.

Step 7: Add a Label for Better Organization (Optional)

The Label field allows you to assign a category or keyword to your variable. Labels facilitate grouping and searching variables in your application, especially when there are a large number.

Example:

You can label your variable with temperature or conversion to find it more easily.

Step 8: Save and Finalize the Variable

Once all the fields are filled, click on Save to add the variable to your application.

Best Practices for Configuring Variables

  • Name variables clearly: Use descriptive names to facilitate code understanding.
  • Verify expressions: Ensure that formulas are correct to avoid runtime errors.
  • Use units and labels: Although optional, they improve readability and organization.
  • Reuse variables: Take advantage of the power of variables by referencing them in other expressions to optimize your code.

Conclusion

Configuring variables is a simple yet powerful approach to enrich and optimize your application. By following the outlined steps and applying these best practices, you can create effective variables and contribute to a more dynamic and functional application.

Feel free to further explore the possibilities offered by expressions and ternary operators to optimize your variables and improve your application's performance.