Variable

Overview

The ScriptVariable class is used either in a global scope under solution or as a form variable within the Servoy environment. It allows for defining and managing variables with properties such as name, scope, and type. The class supports various functionalities, including setting and retrieving the variable’s name and scope with methods like setName() and getScopeName(). It also provides the ability to manage the variable's default value using setDefaultValue() and getDefaultValue(), along with calculating its initial value through the getInitValue() method.

The class handles the type of the variable, ensuring it is correctly set and validated with setVariableType() and getVariableType(). It can also generate string representations of the variable providing useful metadata like type and default value in an HTML format.

Additionally, ScriptVariable supports various annotations which are checked using methods like isPrivate(), isPublic(), and isDeprecated(). The class also includes functionality for handling custom properties, such as a keyword with getKeyword() and setKeyword().

In essence, the ScriptVariable class offers a comprehensive solution for defining and managing variables in the Servoy environment, providing flexibility for visibility, scope, and customization.

Properties Summarized

Type
Name
Summary

Property for setting and getting the jsdoc text (comment) of the script variable.

The default value of the variable.

The name of the variable.

The name of the scope.

The type of the variable.

Properties Detailed

comment

Property for setting and getting the jsdoc text (comment) of the script variable.

Type String the value of the jsdoc text (comment) of the script variable

defaultValue

The default value of the variable.

It is interpreted as a JS expression.

For form variables, setting this property via solutionModel requires the form instances to be destroyed (history.remove("formName")). If you want to use a default value for a newly created variable create the variable using the 3 parameter version newVariable(name,type,defaultValue).

For INTEGER variables it can be an integer constant, like 10 for example. For NUMBER variables it can be a real constant, like 22.41. For DATETIME variables it can be "now", or a JS expression like "new Date()". For TEXT variables it can be any string surrounded with quotes, like "'some text'".

Type String

name

The name of the variable.

Type String

scopeName

The name of the scope.

Type String

variableType

The type of the variable. Can be one of: TEXT, INTEGER, NUMBER, DATETIME or MEDIA.

Type Number


Last updated