Getting script by path
You can use this script operation to get a script from the docstore or in a file system.
Most of the time, this script operation is used together with getFunctionByName()
and invoke()
to start a function in a trigger script.
The directive #include can also be used in a IBM® Product Master script to include another script. This
directive must be the first line in the calling script. The included script can be from the docstore
or from the file system. In the file system, the script path must start with
file://...
. You can use this directive instead of
getScriptByPath()
.
For example, the following trigger script is named
My Library
,
in which a function called lib_add()
is defined in
the following script:function lib_add(a, b)
{
return a + b;
}
In the script sandbox, you can start the function
lib_add()
by
using the following sample script:var MY_LIBRARY_PATH = "scripts/triggers/My Library";
//doc store path
//var MY_LIBRARY_PATH = "file://local/qa2/imports/scripts/myLibrary.wpcs";
//file system path
var MY_FUNCTION_NAME = "lib_add";
var script = getScriptByPath(MY_LIBRARY_PATH);
var func = script.getFunctionByName(MY_FUNCTION_NAME);
var result = func.invoke(1,2);
out.println("result: " + result);
In the script sandbox, you can start the function
lib_add()
by
using #include
as in the following sample script:#include "/scripts/triggers/My Library"out.println("sum : " + lib_add(1,2));
If the script is in the file system at
local/qa2/imports/scripts/myLibrary.wpcs
,
you can use the following sample
script:#include "file://local/qa2/imports/scripts/myLibrary.wpcs"out.println("sum : " + lib_add(1,2));
The
output for these scripts is sum : 3
.