Child pages
  • Implementing Business Logic

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Create a Global Variable (two ways)

From context menu:

  1. From the Solution Explorer tree, navigate to the Active Solution > Globals > variables node node.

  2. Right-click the variables node and select select Create Variable from the pop-up menu.

  3. Choose a variable name, a data type and optionally choose an initial value and click OK. The variable declaration will be generated in the globals.js file, which will be opened in the Script Editor.

From Solution Explorer toolbar:

  1. From the Solution Explorer tree, navigate to the Active Solution > Globals > variables node.

  2. Select the variables node and click the Create Variable button from the lower toolbar in the Solution Explorer.

  3. Choose a variable name, a data type and optionally choose an initial value and click OK. The variable declaration will be generated in the globals.js file, which will be opened in the Script Editor.

Create a Form Variable (two ways) 

From context menu:

  1. From the Solution Explorer tree, navigate to the Active Solution > Forms > myForm > variables node.
  2. Right-click the variables node and select Create Variable from the pop-up menu.
  3. 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

  1. From the Solution Explorer tree, navigate to the Active Solution > Forms > myForm > variables node.
  2. Select the variables node and click the Create VariableOK button from the lower toolbar in the Solution Explorer.
  3. 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 Global Method in one of two ways

From context menu

  1. From the Solution Explorer tree, navigate to the Active Solution > Globals node.
  2. Right-click the Globals node and select Create Method from the pop-up menu.
  3. Choose a method name and click OK. The method declaration will be generated in the globals.js file, which will be opened in the Script Editor.

From Solution Explorer toolbar: 

  1. From the Solution Explorer tree, navigate to the Active Solution > Globals node.
  2. Select the Globals node and click the Create Method button from the lower toolbar in the Solution Explorer.
  3. Choose a method name and click OK. The method declaration will be generated in the globals.js file, which will be opened in the Script Editor.

Create a From Method in one of two ways 

 

From context menu

  1. From theSolution Explorertree, navigate to the Active Solution > Forms > myForm node.
  2. Right-click themyFormnode and selectCreate Methodfrom the pop-up menu.
  3. Choose a method name and clickOK. The method declaration will be generated in themyForm.jsfile, which will be opened in theScript Editor.

From Solution Explorer toolbar: 

  1. From the Solution Explorer tree, navigate to the Active Solution > Forms > myForm node.
  2. Select the myForm node and click the Create Method button from the lower toolbar in the Solution Explorer.
  3. 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

...

Code Block
function nextRecord(){

    var index = controller.getSelectedIndex(); // store the current index

    controller.setSelectedIndex(index+1);      // increment the index by 1

}

The example uses the form's controller object, part part of the Javascript API provided by Servoy.

Developers need not memorize the API or look it up. The scripting APIs are self documenting, and code fragments can easily be inserted into the Script Editor.

Insert a Code Fragment

Any scripting API (including methods written by a developer) can be inserted directly into the Script Editor in two ways.

From context menu:    

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. Active Solution > Forms > myForm > controller).
  2. 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 Solution Explorer toolbar: 

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource.
  2.  In  In the list of methods and properties provided in the lower part of the Solution Explorer, select the method or property that you wish to invoke and click the Move Code button in the lower toolbar of the Solution Explorer. 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.

Insert Sample Code

Any scripting API's commented sample code can be inserted directly into the Script Editor in two ways.

From context menu

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. Active Solution > Forms > myForm > controller).
  2. 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.

From Solution Explorer toolbar: 

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource.
  2. In the list of methods and properties provided in the lower part of the Solution Explorer, select the method or property that you wish to invoke and click the Move Sample button in the lower toolbar of the Solution Explorer. A verbose, commented sample will be copied into the Script Editor.
Tip
titleTip

Any scripting API (including methods written by a developer) can be auto-completed using key strokes.

To use To use auto-complete, begin typing the code you wish to execute, then hit ctrl Ctrl+space on the the keyboard. A type-ahead list of available scripting objects will appear for you to choose choose from as you type. This is a highly productive and accurate way to write code when you have become more familiar with the APIs.

Tip
titleTip

If you are unfamiliar with Javascript syntax, that's OK. In the Solution Explorer, navigate to the JS Lib node. This object contains a list of APIs for dealing with the Javascript language and native data types. It even contains syntax completion for common statements in the Statements node.

Quick Start Video

Suvideo
51_implementing_business_logic.mp4
51_implementing_business_logic.mp4