Creating script parameters

The script based parameter allows the user to manipulate extraction values, or if required extract values from an external source. It is very similar to the script based definition where it uses javascript. But in this case the script must return a list of values or single value. The script parameter can use extractions and other parameters types if required. Use this procedure to create script parameters.

Before you begin

Use the Parameter Administration window to edit process parameters as part of parameter administration.

About this task

Script parameters are very similar to script definitions, but the return type must be a string or a list of strings. Typically you would use script parameters to manipulate extraction data before returning the list of values to an existing native, native command or modelled definition. The script must include a function named calculate that accepts one parameter and returns String or List<String>.
Note: The parameter names are not fixed.
The following example extracts a list of NTP Server IP addresses from the device, parses the last octet of each IP and returns the list.
function calculate(helper) {

importClass(java.util.ArrayList);
var newList = new ArrayList();
var x =0;

var extractList = helper.getExtractionParameter("extractNTPServer").toArray();
//parse out the last octet of IP
for(x in extractList){
  var ip = extractList[x];
  var splitArray = ip.split("\\.");
  newList.add(splitArray[3]);

}

return newList;
}
Restriction: Any calls to helper.addInfo(“message”) within the script parameter will not be shown in results information, as this is only supported in the script definition.

Procedure

This task describes how to create script parameters.

  1. Select Parameter->Parameter Administration.

    The Parameter Administration window displays. Use the following descriptions as a guide to understanding the fields and icons on the Parameter Administration window.

  2. Click the Script Parameters tab.

    All available script parameters are displayed on the Parameter Administration window.

  3. To add a new script parameter, select the New button. The Add Script Parameter Definition window displays.
  4. Use the following descriptions as a guide to understanding the fields on the Add Script Parameter Definition window.
    Name
    Identifier for the script parameter.
    Description
    Narrative to accompany the script parameter.
    Realm
    Realm where the script parameter will be placed
    Script Type
    The only option is JavaScript. JavaScript must be entered here.
    For more information on scripts, see the related links.
    Validate Syntax
    This is used to validate the syntax of the JavaScript entered. See below for an example of a script parameter.
    Script Parameters
    Add parameters.
  5. Click the OK button to confirm the addition of the script parameter. Alternatively, click the Cancel button to cancel.

Example

The following example shows how a script definition can be used to check a device configuration has only one ntp server defined:
function calculate(helper) {

var ntpServerExtractionList = helper.getExtractionParameter("extractNTPServer");
helper.addInfo("Testing device "+helper.getDeviceName());

if(ntpServerExtractionList.size() == 1){
  helper.addInfo("Success = Only one NTP Server defined");
  return true;
}
helper.addInfo("Failed - There are "+ntpServerExtractionList.size()+" NTP servers present");
return false;
}