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.
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;
}