Env - SetVar

Page / - last modified by Outhman Moustaghfir on 2024/01/22 10:09

SetVar

last modified by Outhman Moustaghfir

on 2024/01/22 10:09

Table of Contents

Overview

Parameters

Usage

Retrieving Variable Values

Note

Conclusion

Overview

The SetVar function is used to define and set variables within a scenario. Variables can be classified as either global or local, each serving distinct purposes within the execution of scenarios.

SetVar(variable_name, value, global=False)

variable_name: The name of the variable to be set.

value: The value to assign to the variable.

global (optional): A boolean flag indicating whether the variable should be global. Defaults to False.

Parameters

variable_name: (Type: string) The unique identifier for the variable.

value: (Type: any) The value to assign to the variable.

global: (Type: boolean, Optional) Specifies whether the variable is global or local. Defaults to False.

Usage

Example 1: Setting a Local Variable

<xsl:value-of select=" ixf:SetVar('local_variable', '42')"></xsl:value-of>

This sets a local variable named "local_variable" with a value of 42. Local variables are only accessible within the current scenario.

Example 2: Setting a Global Variable

<xsl:value-of select=" ixf:SetVar('global_variable', 'hello', 'true')"></xsl:value-of>

This sets a global variable named "global_variable" with the value "hello". Global variables can be accessed from the parent scenario.

Retrieving Variable Values

To retrieve the value of a variable, use the GetVar function:

<xsl:value-of select="ixf:GetVar('variable_name')"></xsl:value-of>

variable_name: The name of the variable whose value you want to retrieve.

Note

If global is set to true, the variable will be considered global. Omitting the global parameter or setting it to false makes the variable local.

Conclusion

The SetVar function provides a flexible way to manage variables within scenarios, allowing you to control their scope and access them as needed.