Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scripted Rest Resource when trying to call SLACK API

nicholascer
Tera Contributor
I am trying to integrate Slack with my PDI in such a way that, when i type in the slash command "/incident <INC-number>" I am able to pull forward details about that incident.
 
I have created a Scripted REST Resource and Scripted Rest Service to handle this.
 
I have set the Request URL for my slack app to point to "https://<my-instance>.service-now.com/api/<namespace>/slack_incident_lookup/incident_status"
 
However I am finding that my command and integration is not working. Below is the script I am using, as well as screenshots of my field setups.
Can anyone provide me with tips on how to troubleshoot this, what I might be doing wrong?
 
 
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var parameters = request.queryParams;
var number = parameters.number;
var body = {};

if(!number) {
response.setStatus(400);
body.error = "Missing 'number' parameter";
response.setBody(JSON.stringify(body));
return;
}

//if input provided matches an existing incident, then populate the response body with Number,Short Description, State, and Assignee information


var incident = new GlideRecord('incident');
if(incident.get('number', number)){
body = {
number: incident.number.toString(),
description: incident.short_description.toString(),
status: incident.state.getDisplayValue(),
assignee: incident.assigned_to.getDisplayValue()
};
} else{
body.error = "Incident not found: " + number;
}
response.setHeader('Content-Type', 'application/json');
response.setStatus('200');
response.setBody(JSON.stringify(body));
})(request, response);
NOTE: 
something odd I've notice is that when I leave relative field as '/' the System Logs will return an error message 
Requested URI does not represent any resource: /<namespace>/slack_incident_lookup/incident_status: no thrown error​

But when I populate the relative field on the form as 'incident_status' it does not return any error on the system log, but still does not work.

 

RestResource.PNGScriptedRESTService.PNG

0 REPLIES 0