admin管理员组文章数量:1336304
I'm attempting to use a JS script from Maximo 76 Scripting Features (PDF download).
importPackage(java.util)
importPackage(Packages.psdi.server)
var ctx = new HashMap();
ctx.put("url","http://localhost:7001/maximo/oslc/script/countryapi?_lid=wilson&_lpwd=wilson");
service.invokeScript("LIB_HTTPCLIENT",ctx);
var jsonResp = ctx.get("response");
var countries = JSON.parse(jsonResp);
When I execute the script I get this error:
ReferenceError: "importPackage" is not defined in <eval> at line number 1
Why am I getting this error?
I'm attempting to use a JS script from Maximo 76 Scripting Features (PDF download).
importPackage(java.util)
importPackage(Packages.psdi.server)
var ctx = new HashMap();
ctx.put("url","http://localhost:7001/maximo/oslc/script/countryapi?_lid=wilson&_lpwd=wilson");
service.invokeScript("LIB_HTTPCLIENT",ctx);
var jsonResp = ctx.get("response");
var countries = JSON.parse(jsonResp);
When I execute the script I get this error:
ReferenceError: "importPackage" is not defined in <eval> at line number 1
Why am I getting this error?
Share asked Aug 17, 2019 at 14:24 User1974User1974 3961 gold badge23 silver badges82 bronze badges2 Answers
Reset to default 7Add this to the beginning of the script:
load("nashorn:mozilla_pat.js");
Details:
From Automation Scripts: Compatibility with Maximo 7.6.1:
...the Rhino JavaScript engine was replaced with Nashorn (V8). It turns out that Nashorn does not permit the import of whole Java packages which sheds light on why I was getting the error.
Add the following line to the beginning of your script:
load("nashorn:mozilla_pat.js");
This article references how to properly construct your script to take advantage of the new script engine.
And from Maximo 76 Scripting Features (PDF download).
Java 8 and Nashorn engine:
Some of the above example is written using the jdk 7 based rhino js engine. In jdk 1.8, the rhino engine has been replaced with the Nashorn (V8) engine. For example the importPackage mand will not work there. You would need to use the JavaImporter function to do the same in Nashorn. You can look into this stackoverflow link for more details on what all changed from Rhino to Nashorn that may impact your script code in js:
http://stackoverflow./questions/22502630/switching-from-rhino-to-nashorn
According to Rhino Migration Guide you can try something like this:
var HashMap = Java.type("java.util.HashMap");
because it works like an import, you can use it afterwards:
var ctx = new HashMap();
本文标签: javascriptMaximo JS automation script quotimportPackagequot is not definedStack Overflow
版权声明:本文标题:javascript - Maximo JS automation script: "importPackage" is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742405950a2468823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论