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?

User1974
  • 276
  • 1
  • 17
  • 63
  • Related post here: [Invoke autoscript via URL to create WO](https://community.ibm.com/community/user/iot/communities/community-home/digestviewer/viewthread?MessageKey=a78c727b-d54d-4b8f-b47c-0c2a03469d27&CommunityKey=3d7261ae-48f7-481d-b675-a40eb407e0fd&tab=digestviewer#bma78c727b-d54d-4b8f-b47c-0c2a03469d27) – User1974 Jun 17 '20 at 13:03

3 Answers3

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);
    
nyx69
  • 747
  • 10
  • 21
Kasey
  • 307
  • 1
  • 8
  • 1
    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. – Preacher Oct 17 '19 at 23:16
  • Related article here: https://a3jgroup.com/call-maximo-automation-scripts-from-json-api/ – User1974 Jun 17 '20 at 13:01
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://stackoverflow.com/questions/57537142/maximo-js-automation-script-importpackage-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.

User1974
  • 276
  • 1
  • 17
  • 63
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"
User1974
  • 276
  • 1
  • 17
  • 63