Writing JavaScript Files for Custom Functionality

Client scripts are executed in a separate thread as an HTML 5 Web Worker by executing the main function of the client scripts. The main function is called with a parameter describing the target form/row/field of the user action. This parameter object has the following properties:

  • selection: index of the row in context

  • fieldInfo: object describing the field in context

  • dataTreeId: the id of the data tree in context

  • masterEntityId: the id of the master entity

  • serverSchemaId: id of the schema in context

  • widgetId: id of the widget in context

The fieldInfo property has, in turn, the following properties:

  • columnName: the name of the database table containing the field

  • entityId: the id of the entity containing the field

  • id: the id of the field

  • name: the name of the field

An example object of the main function parameter:

{
"selection": 45,
"fieldInfo": {
columnName: "CD_ID"
entityId: "AE39A4AA6A593B9DCA16F370E56F3D28"
id: "0CB25FF244881F41DE448577FB48C237"
name: "CdId"
}
"dataTreeId" : "65EE6049A5C39AF77E537940A9CC9FE0",
"masterEntityId": "C15079B06FDA5FD35173EBD5E3BC9DB5",
"serverSchemaId": "6C6F63616C6462",
"widgetId": "B424E339BD213982194BA3B7C6336C25"
}

Client scripts can obtain further information about the (broader) context, which can be obtained through functions of the global object called plexusAPI .

Query functions:

  • /*** Gets an entity descriptor. schemaId and entityId specify the entity. callback will be called with the entity descriptor as its sole parameters.*/plexusAPI.getEntity(schemaId, entityId, callback)

  • /*** Gets data for a field in a given row in a given entity.*/plexusAPI.getData = function(schemaId, entityId, rowId, fieldId, callback)

  • /*** Gets the structure definition in the given format (smiles, molfile, sdfile, etc...) at the specified field.*/plexusAPI.getStructure = function(schemaId, entityId, rowId, fieldId, format, callback)

Control functions:

  • /*** Logs a message to the console.*/plexusAPI.log = function(data)

  • /*** Shows a message in an alert box.*/plexusAPI.showMessage = function(data)

  • /*** Opens a new browser window with the given URL.*/exports.openNewWindow = function(url)

Sample script:

function main(data){
plexusAPI.log("Initial data:");
plexusAPI.log(data);

plexusAPI.getEntity(data.serverSchemaId, data.masterEntityId, function(entity){
plexusAPI.log("Entity:");
plexusAPI.log(entity);

plexusAPI.getData(data.serverSchemaId, data.fieldInfo.entityId, data.selection, data.fieldInfo.id, function(data){
plexusAPI.log("Data:");
plexusAPI.log(data);
});
});
};