Custom REST service with Automation Script

The REST APIs have a tight integration with the automation scripts. Automation scripts can be used to develop custom APIs. The following example call describes how automation scripts interact with REST APIs. You can also use automation scripts for implementing custom queries and custom actions.

JavaScript language is always the preferred choice for integration scripts since it provides native functions to manage JSON objects.

To find the total number of work that is in progress and service requests in a given site, you need to create an API since there is no out-of-the-box API for this task. Create the following Automation Script:

  • Script: MXD_COUNTWOSR
  • Description: Count WOs and SRs
  • Language: JavaScript
load("nashorn:mozilla_compat.js");
importPackage(Packages.psdi.server);

var resp = {};
var site = request.getQueryParam("site");
var woset = MXServer.getMXServer().getMboSet("workorder", request.getUserInfo());
woset.setQbe("siteid", "="+site);
var woCount = woset.count();
resp.wocount = woCount;
var srset = MXServer.getMXServer().getMboSet("sr", request.getUserInfo());
srset.setQbe("siteid", "="+site);
var srCount = srset.count();
resp.srcount = srCount;
resp.total= srCount+woCount;
var responseBody = JSON.stringify(resp);

After you save the script, open your browser and initiate the GET request to validate the results.

GET /oslc/script/MXD_COUNTWOSR?site=BEDFORD

If you have an API token you can simply build a URL like this and paste it in a web browser.

http://mxserver/maximo/oslc/script/MXD_COUNTWOSR?site=BEDFORD&apikey=ski98ju29ls9r157kkl8q6u738rjcfgh8c3aqo30

The response in JSON is shown:

{
"wocount" :100,
"srcount" :20 ,
"total" : 120
}
Custom REST service with Automation Script

One thought on “Custom REST service with Automation Script

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top