Page History
...
Note | ||
---|---|---|
| ||
Developers who are familiar with Javascript may cite issues with browser support and speed of execution. However, it is worth noting that Servoy does not deploy any Javascript. All code written in Servoy is deployed using Mozilla's Rhino project, which is an open-source, Java-based Javascript implementation. This means that:
|
Scope
Scope defines the domain in which code is executed and subsequently determines the namespace by which scripted objects are referenced. Javascript code (functions and variables) may be defined in the following two scopes:
solution-wide scopes:
Code Block title Global Scope: Found in the globals.js file and accessible via the namespace globals, i.e. scopes.globals.createNewCustomer(); // invokes the global method defined in the 'globals' scope
form scopes
Code Block title Form Scope: Found in the formName.js file and accessible via the namespace forms.formName, i.e. forms.customers.controller.newRecord(); // invokes a form object from another scope
compared to:
Code Block |
---|
function createNewCustomer(){ // a method defined within the 'customers' form scope controller.newRecord(); // invokes the same form object from within the form's scope. Notice the fully qualified namespace is NOT required } |
Creating a Variable
Create a
...
Scope Variable (two ways)
From context menu:
From the Solution Explorer tree, navigate to the Active Solution > Globals active solution > Scopes > myScope > variables node.
Right-click the variables node and select Create Variable from the pop-up menu.
Choose a variable name, a data type and optionally choose an initial value and click OK. The variable declaration will be generated in the globalsmyScope.js file, which will be opened in the Script Editor.
From Solution Explorer toolbar:
From the Solution Explorer tree, navigate to the Active Solution > Globals active solution > Scopes > myScope > variables node.
Select the variables node and click the Create Variable button from the lower toolbar in the Solution Explorer.
Choose a variable name, a data type and optionally choose an initial value and click OK. The variable declaration will be generated in the globalsmyScope.js file, which will be opened in the Script Editor.
Create a Form Variable (two ways)
...
- From the Solution Explorer tree, navigate to the Active Solution active solution > Forms > myForm > variables node.
- Right-click the variables node and select Create Variable from the pop-up menu.
- Choose a variable name, a data type and optionally choose an initial value and click OK. The variable declaration will be generated in the myForm.js file, which will be opened in the Script Editor.
From Solution Explorer toolbar:
- From the Solution Explorer tree, navigate to the Active Solution active solution > Forms > myForm > variables node.
- Select the variables node and click the Create VariableOK button from the lower toolbar in the Solution Explorer.
- Choose a variable name, a data type and optionally choose an initial value and click. The variable declaration will be generated in the myForm.js file, which will be opened in the Script Editor.
Creating a Method
Create a
...
Scope Method in One of Two Ways
From context menu:
- From the Solution Explorer tree, navigate to the Active Solution > Globals active solution > Scopes > myScope node.
- Right-click the Globals myScope node and select Create Method from the pop-up menu.
- Choose a method name and click OK. The method declaration will be generated in the globalsmyScope.js file, which will be opened in the Script Editor.
From Solution Explorer toolbar:
- From the Solution Explorer tree, navigate to the Active Solution > Globals active solution > Scopes > myScope node.
- Select the Globals myScope node and click the Create Method button from the lower toolbar in the Solution Explorer.
- Choose a method name and click OK. The method declaration will be generated in the globalsmyScope.js file, which will be opened in the Script Editor.
Create a From Method in One of Two Ways
...
- From theSolution Explorertree, navigate to the Active Solution active solution > Forms > myForm node.
- Right-click themyFormnode and selectCreate Methodfrom the pop-up menu.
- Choose a method name and clickOK. The method declaration will be generated in themyForm.jsfile, which will be opened in theScript the Script Editor.
From Solution Explorer toolbar:
- From the Solution Explorer tree, navigate to the Active Solution > Forms > myForm node.
- Select the myForm node and click the Create Method button from the lower toolbar in the Solution Explorer.
- Choose a method name and click OK. The method declaration will be generated in the myForm.js file, which will be opened in the Script Editor.
Implementing Basic Business Logic
...
- From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. Active Solution active solution > Forms > myForm > controller).
- In the list of methods and properties provided in the lower part of the Solution Explorer, right-click the method or property that you wish to invoke and select Move Code. The code will be copied into the Script Editor and will be referenced with the correct namespace for the current scope. You may need to fill in specific arguments.
...
- From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. Active Solution active solution > Forms > myForm > controller).
- In the list of methods and properties provided in the lower part of the Solution Explorer, right-click the method or property that you wish to invoke and select Move Sample. A verbose, commented sample will be copied into the Script Editor.
...