5.8 Performing Operations with Menu Options

A script can perform operations defined as a menu option for a Operations Center element by using the operation command name.

5.8.1 Using the Perform Method

The perform method takes a session as its first argument, followed by the command name of the operation to perform. An optional parameter for the function is an array of any length, if the operation supports it.

perform( session, operationName, /* array */ alarms, /* array */ params ) 
Example:
js> // Find the "users" group.
js> var users = formula.Administration.findElement( 'group=users/groups=Groups/security=Security' )
js> // Tell the group to force off all sessions.
js> var result = users.perform( session, 'Connect|ForceOff', [], [] )
js> writeln( result )
Warning. You are not able to logout your own session.

There were no sessions active with the given account users
js>

5.8.2 Using Customized Operations

If an operation is defined for an element (it is displayed in the user interface), you can invoke it programmatically via a script. For example:

// Assume there is an operation named ‘Cut Ticket' on the alarms 
// of the first (and only) adapter element, and that there are valid
// alarms on this adapter.
var someAdapterElement = formula.Elements.children[0]
var alarms = someAdapterElement.alarms
someAdapterElement.perform( session, 'Cut Ticket', [ alarms[0] ], [] )

This script performs three actions:

  1. Locates a top-level adapter element; it assumes there is at least one.

  2. Obtains the alarms for this element; it assumes there is at least one.

  3. Performs the Cut Ticket operation on this alarm, through the element. It passes only one alarm.

5.8.3 Loading Another Script

If the only intent is to load another script with the operation, use the @ function. For example:

@login.fs

However, to load the script from within a script, it is necessary to use the load function. For example:

formula.log.info( "loading" );
load( 'test.fs' );
formula.log.info( "done" );

5.8.4 Using Hidden Operations

To specify an operation for an element that is not visible in the user interface, but is usable from scripts, set the “hidden” property of the operation.