Script tool examples

Script tool syntax follows JavaScript rules, and you can create many different script tools to extract data from events, as illustrated by these examples.

Sample: Event scratchpad

This JavaScript code sample creates a simple scratchpad tool and illustrates the potential of script tools.

After you execute the scratchpad tool against a selected event, below the AEL a new area is displayed containing event data, such as a summary of the event, the time of occurrence, the node where the event occurred, and its severity. The event data is added to the page using the Document Object Model (DOM).

The script commands are as follows:
var str = 'Event \'{@Serial}\' at Node \'{@Node}\' has Summary \'{@Summary}\', Severity \'{@Severity}\' and last occurred on ' + new Date({@LastOccurrence}*1000);

var scratchpad = document.getElementById("scratchpad_{$param.EntityName}");

if (scratchpad == null)
{
	scratchpad = document.createElement("div");
	scratchpad.setAttribute( "id", "scratchpad_{$param.EntityName}" );
	scratchpad.setAttribute( "style", "overflow:auto;height:200px;border-width:1px;border-style: solid;margin:5px;padding:5px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:0.7em;" );

	var header= document.createElement("h2");
	header.appendChild( document.createTextNode( "Scratch Pad for entity {$param.EntityName}" ) );	scratchpad.appendChild( header ); 
	document.body.appendChild(scratchpad);
}

var div = document.createElement("div");
var dl = document.createElement("dl");

var dt = document.createElement("dt");
dt.appendChild( document.createTextNode( new Date() ) ); 
dl.appendChild(dt);

var dd = document.createElement("dd");
dd.appendChild( document.createTextNode( str ) ); 
dl.appendChild(dd);

div.appendChild(dl);

scratchpad.appendChild(div);

Sample: Event NodeClickedOn

This JavaScript code sample sends extra data fields, which are not displayed in the Event Viewer, with NodeClickedOn to wired portlets.

Note: If comments are required you must use /**/ syntax, rather than the // syntax.
The script commands are as follows:
var event = {
  name: "http://ibm.com/tip#NodeClickedOn",
  payload: { product: { OMNIbusWebGUI: { displaycontext: {
           "filterName" : "{@Node}",
           "filterType" : "user_transient",
           "registerFilter" : "true",
           "sql" : "PhysicalPort = {@PhysicalPort}",
           "forceOverwrite" : "true",
           "viewName" : "Default",
           "viewType" : "global",
           "dataSource" : "OMNIBUS"
           } } } } };
{$param.portletNamespace}sendPortletEvent(event);