Maximo Open Forum

 View Only

 How do I Get the Script Service within an Object Structure Inbound Automation Script?

Jump to  Best Answer
  • Administration
  • Integrations
Jared Schrag's profile image
Jared Schrag posted 08-26-2024 19:54

It seems as if the implicit variable service is not in the context for Automation Scripts that process inbound Object Structures. Am I missing something? Is there a proper way I can get an instance of the ScriptService object? I need to use the ScriptService instance to invoke another Automation Script during inbound Object Structure processing.

Jason VenHuizen's profile image
Jason VenHuizen  Best Answer

Hi Jared,

It depends on where you are in the process, but the context that is passed into the various function call backs typically serves to provide the the same functionality as the normal implicit service class.  That said, the service variable only provides access to things you can do without it so it is sort of unnecessary and only there for convenience.

Here is how to do that on your own.

var ScriptCache = Java.type("com.ibm.tivoli.maximo.script.ScriptCache");
var ScriptDriverFactory = Java.type("com.ibm.tivoli.maximo.script.ScriptDriverFactory");

var result = invokeScript("YOUR_SCRIPT_NAME_HERE");

function invokeScript(scriptName) {
    var scriptInfo = ScriptCache.getInstance().getScriptInfo(scriptName);
    if (scriptInfo) {
        var context = new HashMap();
        ScriptDriverFactory.getInstance().getScriptDriver(scriptName).runScript(scriptName, context);
        return context;
    } else {
        return null;
    }
}

or 

from com.ibm.tivoli.maximo.script import ScriptCache, ScriptDriverFactory

def invokeScript(scriptName):
    scriptInfo = ScriptCache.getInstance().getScriptInfo(scriptName)
    if (scriptInfo):
        var context = new HashMap()
        ScriptDriverFactory.getInstance().getScriptDriver(scriptName).runScript(scriptName, context)
        return context
    else:
        return null    

result = invokeScript("YOUR_SCRIPT_NAME_HERE")

As a fun addition, if you use JavaScript you can inline one script into another like so:

// Import the ScriptCache Java class.
ScriptCache = Java.type('com.ibm.tivoli.maximo.script.ScriptCache');

// Load the Excel library inline with the current script.
load({ script: ScriptCache.getInstance().getScriptInfo("YOUR_SCRIPT_NAME_HERE").getScriptSource(), name: "YOUR_SCRIPT_NAME_HERE" });
Jared Schrag's profile image
Jared Schrag

Thanks @Jason VenHuizen!

After I dug into the JavaDocs, I found that the context (ctx)  given for the afterMboData() function extends the very ScriptService I was inquiring about :D

You additional feedback is quite helpful as well, thanks!