Notifications

387 views

Description

This article explains how to achieve the following using the 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.

Release or Environment

All releases supporting RESTMessageV2

Resolution

Use this script as a reference and modify it as needed:

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);
}

 

Additional Information

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

Article Information

Last Updated:2020-01-29 05:42:31
Published:2020-01-27