Automation scripts

The REST APIs have a tight integration with the automation scripts. Automation scripts can be used to develop custom APIs.

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. Since this is a REST API with a JSON response, you can use the JavaScript language for scripting. You call this API countofwoandsr.

GET /oslc/script/countofwoandsr?site=ABC

The response in JSON is shown:

{
  "wocount": 100,
  "srcount": 20,
  "total": 120
}

You can write the following script for this API:

Script Name: countofwoandsr

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.

You can also use automation scripts for implementing custom queries and custom actions.