Buttons and scripts are functionally the same with a few noteworthy differences. Script function can change depending on where it is installed (database root vs. a data tree root). A button is a script attached to a form and has an absolute root. The resultset is defined as the resultset that is applied to the form, as this represents a snapshot of the data, and thus the vertex is already defined. In the case of a script, you must specify the vertex, and then the resultset. A script, however, will automatically inherit the dataTree definition based on where it is installed. Since a resultset could represent data relating to a different dataTree, the dataTree must be defined for a button.
A new button will contain the code for how to move to the next record in a selection. This is commented out, but provides some framework. Of particular importance are the definitions of the resultset and datatree. The differences in base variables are shown below.
Additional information can be also found in user documentation: WBButtonWidget.
Script | Button | |
---|---|---|
Provided Variables |
|
Only through closure parameters such as widget |
Result Set | (default RS for dataTree)
def parent = dataTree.rootVertex.entity
|
def rs = widget.form.resultSet |
DataTree | (inherited) | def dataTree = rs.dataTree |
Automatically imported packages | Packages from DIF API:
Packages from Commons - NetBeans related
|
All mentioned |
Buttons react to various events, unlike scripts which run top to bottom. You can handle these events by creating closures which get executed as appropriate. New buttons come with example code for each of the closures: