Notifications

26 views

Description

This article explains how to achieve the following using REST API:

  1. Automate calling ServiceNow Excel Web Service via script
  2. Download the generated excel file
  3. Attach it to a specific record e.g. incident/problem/change etc.

Procedure

Please use below script as a reference and modify it as per your need

try { 
   var request = new sn_ws.RESTMessageV2();
 var instanceUrl = "https://instance.service-now.com/";
   request.setEndpoint(instanceUrl + "incident_list.do?EXCEL&sysparm_query=active=true");
   request.setHttpMethod("GET");

   var user = "username";
   var password = "password";

   request.setBasicAuth(user, password);
   //request.setRequestHeader("Accept", "application/json");

   request.saveResponseBodyAsAttachment("table_name","record sys_id",'file_name');

   var response = request.execute();
   var httpStatus = response.getStatusCode();
   gs.print(httpStatus);
} catch (ex) {
     var message = ex.getMessage();
     gs.print(message);
}

 

Applicable Versions

Application to all the version supporting RESTMessageV2

 

Additional Information

This is a server side script therefore, please use this piece of code in a Business rule, Script Include or in any other scripted area of your choice.

Article Information

Last Updated:2019-06-27 02:33:13
Published:2019-06-27