vars
Provides access to JDito variables within JDito processes. Use this class to get, set, or check the existence of variables in JDito processes.
Methods
dependOn
dependOn(...
pNames):void
Creates dependencies on the specified variables.
This method ensures that the system tracks changes to these variables and marks dependent values to be recalculated when they are read the next time. This is useful when you want a process to be automatically recalculated when certain variables are modified, but the exact value of these variables is ignored.
Note: When a variable is already fetched with get in the same process, this is unnecessary, because these methods automatically create a dependency.
Parameters
...string[]The variable names to create dependencies on
Returns
voidThrows
May throw an exception.
dependOnRowChange
dependOnRowChange():
void
Creates a dependency on the loaded row. This method ensures that a field will be calculated for every single row when multiple rows are loaded (for example in a table). Note: When the field already depends on the UID, this has no effect because it will be calculated for every row anyway.
Returns
voidThrows
May throw an exception.
exists
exists(
pName):boolean
Checks whether a variable exists in the current context. Note: This check is generally unnecessary for variables that are guaranteed to exist, such as field and parameter variables in entity processes, or standard system variables. Use this method primarily for dynamically created variables (context and global variables).
Parameters
string | number | booleanThe variable name ($local, $global, $sys, $context, etc.)
Returns
booleantrue if the variable exists; false otherwise
Throws
May throw an exception.
Example
if (vars.exists("$context.histories"))
{
result.string(vars.getString("$context.histories"));
}
get
get(
pName):any
Retrieves the value of a variable in its original type.
This method preserves the variable's data type (object, string, number, boolean, etc.), unlike getString which converts everything to a string.
When used in a process that results in a variable itself (for example the valueProcess of a field), it creates an internal dependency, allowing the system to know when to recalculate the field. Note: Variables with $field and $param prefixes are always returned as strings.
Parameters
string | number | booleanThe variable name (supports $field, $param, $local, $sys, $global, $context prefixes)
Returns
anyThe variable's value in its original data type (object, string, number, boolean, etc.)
Throws
May throw an exception.
Example
// Store and retrieve complex objects
let info = { contactId: "id1234" };
vars.set("$global.userinfo", info);
let contactId = vars.get("$global.userinfo").contactId; // returns "id1234"
// Query existing variables
let ids = vars.get("$sys.selection"); // returns array of selected row IDs
let uid = vars.get("$sys.uid"); // returns current UID
let projectId = vars.get("$param.projectId"); // returns a string
getString
getString(
pName):string
Retrieves the value of a variable as a string.
Any non-string value is automatically converted to its string representation. For complex objects, this performs a string conversion which may not preserve the original data type.
Note: Use get when no string-conversion is required (entity fields and parameters are always strings).
Parameters
string | number | booleanThe variable name (examples: $local.myVar, $global.config, $sys.uid, $context.data)
Returns
stringThe variable's value converted to a string
Throws
May throw an exception.
resolveVariables
resolveVariables(
pText):string
Resolves variable references within a string by replacing them with their values.
Variable names are prefixed with '$' (e.g., $sys.user, $field.name). To include a literal '$' character in the result, escape it with a backslash (\$). Recommendation: For modern JavaScript code, consider using template literals instead
Parameters
string | number | booleanThe string containing variable references to resolve
Returns
stringThe string with all variable references replaced by their values
Throws
May throw an exception.
Example
// Using this method:
let message = vars.resolveVariables("Your login is $sys.user");
// Using template literals (recommended):
let message = `Your login is ${vars.get("$sys.user")}`;
set
set(
pName,pValue):void
Creates or updates a JDito variable. The variable scope is determined by its prefix:
-
$global - Session-wide scope
-
$context - Context-wide scope
-
$local - Process scope (rarely used)
Parameters
string | number | booleanThe variable name; must have a prefix ($local, $context, or $global) followed by a dot and the variable name
anyThe value to assign to the variable
Returns
voidThrows
May throw an exception.
Example
// Create a global variable
vars.set("$global.isGuest", true);
// Create a context variable
vars.set("$context.activityCount", 16);