A field can be associated with a number of scripts.
The scripts fall into a number of groups.
Note: you need to be the owner of the field and to have turned off session protection to update scripts and their bindings.
Derivation scripts
These are used to create new values. There are three different scripts:
- Member Type Derivation Script is used to create new values on the item that uses this field. This is the commonest form of derivation script.
- Instance Derivation Script is used to create new values on the field itself. Use this with caution – it is easy to get wrong.
- Member Type Node Type Derivation Script is used to create new values on node types that use this field.
Extension scripts
Extension scripts are used to create new output associated with the field. They are described in Extension scripts. Four scripts can be entered:
- Member Type Extension Script
- Member Type Edit Extension Script
- Member Extension Script
- Member Edit Extension Script
In many cases, the Display Script Field type provides a convenient alternative to using extension scripts.
Validation scripts
Validation scripts are used to validate data entered into the field. They are described in Validation scripts. Two scripts can be entered:
Column script
Use Column Script to control how the field is shown in tables.
Column scripts are described in Table views and columns. The field is automatically added as a source column for the table. You can reference the field itself using application.getSourceNode(). The script below illustrates a simple column script, which in this case shows a value in an information box.
/**
* Show the value in an info box
*/
var field = application.getSourceNode();
application.get('caller').register({
init: function() {
this.columnNumber = this.resultSet.getColumnNumber(field);
},
getColumns: function() {
return [
{
name: this.name ,
reference: this.column.getNodeReference()
}
];
},
getRow: function(rowNumber) {
var value = this.resultSet.getValue(rowNumber,this.columnNumber);
if ( value != null ) {
var s = '';
s += '<div class="alert alert-info">';
s += application.escape(value);
s += '</div>';
var row = {};
row[this.column.getNodeReference()] = s;
return row;
}
}
});
If you don't set a column script, a suitable default display will be generated.
Only use field column scripts when you always want to replace the default display with a different one. For finer control, create a standalone column script.
If you use Column Script, you cannot also use the general Script.
General script
The general Script can also be entered for a member type, which can be used for any purpose.