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:

  • Description: Count WOs and SRs
  • Language: JavaScript

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; srCount+woCount;
var responseBody = JSON.stringify(resp);

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


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


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