Run an automation script via a URL
Asked Answered
N

3

5

Maximo 7.6.1.1:

I want to run a Maximo automation script by invoking a URL in a separate system.

Is it possible to do this?

Nevsa answered 17/10, 2019 at 17:31 Comment(1)
Related post here: Invoke autoscript via URL to create WONevsa
H
6

This is a great use-case and something that we've been working through in the last few days.

  1. Create automation script. - mine is called automation_api_test
  2. Manually invoke it through the API using a browser to make sure that you can actually get it to run. (%servername%/maximo/oslc/script/automation_api_test?var1=1212321232&var2=1555&site=OPS&_lid=wilson&_lpwd=wilson)
  3. Script it like you would your regular automation script. Here's one that can read in a few parameters from the URL and use those to perform operations in the core system.

    importPackage(Packages.psdi.server);
    importPackage(Packages.psdi.util.logging);
    
    var resp = {};
    // Get the Site ID from the Query Parameters
    //var site = request.getQueryParam("site");
    
    var var1 = request.getQueryParam("var1");
    var var2 = request.getQueryParam("var2");
    var site = request.getQueryParam("site");
    //var zxqponum = request.getQueryParam("ponum");
    
    //logger.debug(zxqprinter);
    service.log("TESTING script Params" + request.getQueryParams());   
    service.log("var1 " + request.getQueryParam("var1"));
    service.log("var2 " + request.getQueryParam("var2"));
    
    //count the number of WO's in the site
    var woset = MXServer.getMXServer().getMboSet("WORKORDER", request.getUserInfo());
    woset.setQbe("SITEID","="+site);
    var woCount = woset.count();
    resp.wo_count = woCount;
    woset.close();
    
    // Get Total Count
    resp.total = woCount;
    //create the response - still not sure why I had to append the vars to a string.
    
    resp.var1= "" + var1;
    resp.var2= "" + var2;
    resp.site= "" + site;
    
    var responseBody = JSON.stringify(resp);
    
Hesychast answered 17/10, 2019 at 18:27 Comment(2)
Normally you append variables to a string to cast the type of the variable to string. I haven't looked it up, but I expect request.getQueryParam() may return a byte[] not a Javascript string.Theotokos
Related article here: a3jgroup.com/call-maximo-automation-scripts-from-json-apiNevsa
N
0

Here's an expanded version of Kasey's answer.

Create a sample automation script in Maximo:

  1. Automation Scripts >> More Actions >> Create >> Script
  2. Script [name]: HELLOWORLD
  3. Script Language: js
  4. Paste in this code:

//THIS IS JAVASCRIPT! NOT JYTHON!

//load("nashorn:mozilla_compat.js"); //More info about this here: https://mcmap.net/q/2036154/-maximo-js-automation-script-quot-importpackage-quot-is-not-defined

//importPackage(Packages.psdi.server);
//importPackage(Packages.psdi.util.logging);
    
var resp = {};
var var1 = request.getQueryParam("var1");

resp.var1= " " + var1 + " World!";
var responseBody = JSON.stringify(resp);
  1. Click Create

Try out a URL:

This URL will send the word "Hello" to the automation script. The automation script will append the word " World!" onto "Hello".

The phrase, "Hello World!" is returned.

  1. In a browser, run this URL: http://yourhostname:1234/maximo/oslc/script/helloworld?var1=Hello&_lid=wilson&_lpwd=wilson
  • Replace yourhostname with your host name
  • Replace 1234 with your port number
  • Replace maximo with the appropriate value.
  1. The URL request should return this JSON object to the browser:

{"var1":" Hello World!"}

  1. From there, create a hyperlink in a separate system (using the above URL). And click it to run the automation script.
  • If the last line in the script were to be deleted, nothing would be returned to the browser.

Note:

The URL only seems to work for me under the WILSON user. It doesn't work with my own user:

{"oslc:Error":{"oslc:statusCode":"401","spi:reasonCode":"BMXAA7901E","oslc:message":
"You cannot log in at this time. Contact the system administrator.","oslc:extendedError"
:{"oslc:moreInfo":{"rdf:resource":"http:\/\/something\/maximo\/oslc\
/error\/messages\/BMXAA7901E"}}}}

Best guess is: my user is not set up correctly.

Nevsa answered 17/10, 2019 at 22:44 Comment(0)
N
0

Here's a really simple JavaScript example:

responseBody = "asdf";

enter image description here

Then just run the URL in a browser (or somewhere else like an automation script in Maximo or a Python script in GIS).

https://<<my host>>/maximo/oslc/script/testscript

enter image description here


It's pretty much the same for Python (no semi-colon):

responseBody = "asdf"
Nevsa answered 16/11, 2021 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.