Derivation scripts

Derivation scripts are used to apply derivations to data.

There are three forms of derivation script:

  • Member type derivations, held on the Member Type Derivation Script (system.MEMBER_TYPE_DERIVATION_SCRIPT) member of the member type.
  • Node type derivations, held on the Type Derivation Script (system.TYPE_DERIVATION_SCRIPT) member of the node type.
  • Instance derivations, held on the Instance Derivation Script (system.INSTANCE_DERIVATION_SCRIPT) member of the node itself. This is deprecated, and will be removed from later version of Metrici.

These are applied in the order shown above. The member type derivation scripts are applied according to the member type derivation priority, then any type-level derivations are added, then any instance level derivations.

When the derivation script is called, the context is set to the node for which derivation is being performed. This is a Script Node Writable Derived object, and can be used to set the derived members.

This node is also available in read-only form from application.get('contextNode') as a Script Node object.

For member type derivations, the member type is available from application.get('contextMemberType'), also as a ScriptNode object.

If these return any errors, the Error (system.NODE_ERROR) derived member will be set (the derivation scripts may set this field directly if they wish, though this is not generally recommended). This will then be shown when the node is displayed.

The script below provides a very simple example of a member type derivation script. It reads the value of the member type, and uses this to set the node name.

var context = application.getContext();
var memberType = application.get('contextMemberType');
var name = context.getValue(memberType);
if ( name != null ) { context.setValue('system.NODE_NAME',name);

All derivation scripts run under the authority of the node owner.

Member type node type derivation

When node types are derived, the Member Type Node Type Derivation (library.core.MemberTypeNodeTypeDerivation) member type of the node type's type calls the Member Type Node Type Derivation Script (library.core.MemberTypeNodeTypeDerivationScript) method of each member type in turn. Member types can participate in the derivation of node types that use them by writing a derivation script in Member Type Node Type Derivation Script (library.core.MemberTypeNodeTypeDerivationScript).

Within a member type node type derivation, the node type is passed as the context, and the member type as the context member type.