Issue
This article explains how to achieve the following using the REST API:
- Automate calling ServiceNow Excel Web Service via script
- Download the generated Excel file
- Attach it to a specific record e.g. incident/problem/change etc.
Release
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);
}
Related Links
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.