11.3 Use Case: Invoking a Server-Side Script from a Client Script

Sometimes a client-side script needs to invoke a script that normally runs on the Operations Center server. In this scenario, the client might or might not need to pass information to the server-side script.

To invoke a script that normally runs on the Operations Center server:

  • Create an operation and assign it to an element in the Operations Center Administration user interface. Consider making this script hidden, because it might not be useful to call unless programmatic input is supplied. This can be done by modifying the operations.ini and adding hidden=true to the script.

  • The client-side script can then find the element that has the operation defined, hard-coding the element dname to look up the element, if necessary. The perform() method is then called on this element, passing the appropriate parameters.

A few examples:

// Find the "server" element.
var server = formula.Administration.findElement( 'formulaServer=Server' )

// Acknowledge an alarm.
element.perform( session, ‘Ack’, [alarm], [])

In the above example, Ack is the operation name, the first [] argument is an array of alarms, and the second[] argument would pass operation arguments if they were required.

// Call custom script-based operation to do something interesting for us.
server.perform( session, 'Do That', [], [ 'One Argument', 'Another Argument' ] )

In this last example, Do That is the operation name, the first [] argument is an array of alarms which we left as an empty array since this is not an alarm-based operation, and lastly the second[] argument are optional operation arguments that are passed as a string array. The arguments appear in the target operation as the predefined script variable args, where args[0] and args[1] correspond to One Argument and Another Argument.