通过URL运行自动化脚本

问题描述 投票:5回答:2

Maximo 7.6.1.1:

我想通过在单独的系统中调用URL来运行Maximo自动化脚本。

可以这样做吗?

url parameters configuration integration maximo
2个回答
6
投票

这是一个很好的用例,最近几天我们一直在努力。

  1. 创建自动化脚本。 -我的名为Automation_api_test
  2. [使用浏览器通过API手动调用它,以确保您可以实际运行它。 (%servername%/ maximo / oslc / script / automation_api_test?var1 = 1212321232&var2 = 1555&site = OPS&_lid = wilson&_lpwd = wilson)
  3. 像编写常规自动化脚本一样编写脚本。这是一个可以从URL读取一些参数并使用它们在核心系统中执行操作的参数。

    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);
    

0
投票

这里是Kasey答案的扩展版本。

在Maximo中创建示例自动化脚本:

  1. 自动化脚本>>更多操作>>创建>>脚本
  2. 脚本[名称]:HELLOWORLD
  3. 脚本语言:js
  4. 粘贴此代码:

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. 单击创建

尝试URL:

此URL将把单词“ Hello”发送到自动化脚本。自动化脚本将附加单词“ World!”。转到“你好”。

这句话,“世界你好!”返回。

  1. 在浏览器中,运行以下URL:http://yourhostname:1234/maximo/oslc/script/helloworld?var1=Hello&_lid=wilson&_lpwd=wilson
    • 用主机名替换yourhostname
    • 用端口号替换1234
    • 用适当的值替换maximo
  2. URL请求应将此JSON对象返回给浏览器:

    {"var1":" Hello World!"}

    ] >>
  3. 从那里,在单独的系统中创建超链接(使用上面的URL)。然后单击它以运行自动化脚本。

  • 如果要删除脚本的最后一行,则不会向浏览器返回任何内容。

注意:

URL在WILSON用户下似乎只对我有用。它不适用于我自己的用户:

{"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"}}}}

最好的猜测是:我的用户设置不正确。

© www.soinside.com 2019 - 2024. All rights reserved.