问题
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?
回答1:
This is a great use-case and something that we've been working through in the last few days.
- Create automation script. - mine is called automation_api_test
- 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)
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);
回答2:
Here's an expanded version of Kasey's answer.
Create a sample automation script in Maximo:
- Automation Scripts >> More Actions >> Create >> Script
- Script [name]: HELLOWORLD
- Script Language: js
- 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);
- 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.
- 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.
- Replace
The URL request should return this JSON object to the browser:
{"var1":" Hello World!"}
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.
来源:https://stackoverflow.com/questions/58437933/run-an-automation-script-via-a-url