-
-
Save heitortsergent/e7b361243bac7cd57fc8df5cb3cd8c3f to your computer and use it in GitHub Desktop.
A sample ServiceNow JavaScript script that receives a Runscope Webhook Notification and creates a ServiceNow incident based on it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { | |
var apiKey = request.queryParams['apiKey']; | |
var secret = '<guid>'; | |
if (apiKey == secret) { | |
gs.info("Runscope Webhook Received"); | |
var event = request.body.data; | |
var inc = new GlideRecord('incident'); | |
inc.initialize(); | |
var short_description = "Runscope Webhook - "; | |
short_description += event.test_name; | |
inc.short_description = short_description; | |
inc.description = event.bucket_name + " - " + event.test_name; | |
inc.work_notes = "Test run URL: " + event.test_run_url; | |
inc.number = event.test_run_id; | |
inc.state = 1; | |
inc.impact = 2; | |
inc.urgency = 2; | |
inc.priority = 2; | |
// optional - specific person to assign the incident to | |
// inc.assigned_to = '<email>'; | |
inc.assignment_group.setDisplayValue('<group>'); | |
var comments = "Runscope Test URL: " + event.test_url; | |
comments += "\nRunscope Test Run URL: " + event.test_run_url; | |
inc.comments = comments; | |
inc.insert(); | |
} else { | |
gs.warn("Invalid API Key for Runscope Webhook"); | |
} | |
// Runscope expects a 200 status code response back | |
response.setStatus(200); | |
})(request, response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment