Skip to content

Instantly share code, notes, and snippets.

@voipnorm
Last active October 21, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voipnorm/cb6f52364936eec8e87c6fcceb2ad0e2 to your computer and use it in GitHub Desktop.
Save voipnorm/cb6f52364936eec8e87c6fcceb2ad0e2 to your computer and use it in GitHub Desktop.
function getServiceNowIncidentIdFromURL(url){
return xapi.command('HttpClient Get', { 'Header': [CONTENT_TYPE, SERVICENOW_AUTHTOKEN] , 'Url':url, 'AllowInsecureHTTPS': 'True'});
}
function raiseTicket(message){
console.log('Message raiseTicket: ' + message);
var messagecontent = { description: systemInfo.softwareVersion , short_description: message };
xapi.command('HttpClient Post', { 'Header': [CONTENT_TYPE, SERVICENOW_AUTHTOKEN] , 'Url':MONITORING_URL, 'AllowInsecureHTTPS': 'True'}
, JSON.stringify(messagecontent)).then(
(result) => {
const serviceNowIncidentLocation = result.Headers.find(x => x.Key === 'Location');
var serviceNowIncidentURL = serviceNowIncidentLocation.Value;
var serviceNowIncidentTicket;
getServiceNowIncidentIdFromURL(serviceNowIncidentURL).then(
(result) => {
var body = result.Body;
console.log('Got this from getServiceNowIncidentIdFromURL: ' + JSON.stringify(result));
serviceNowIncidentTicket = JSON.parse(body).result.number;
xapi.command("UserInterface Message Alert Display", {
Title: 'ServiceNow receipt'
, Text: 'Your ticket id is ' + serviceNowIncidentTicket + '. Thanks for you feedback! Have an awesome day!'
, Duration: 10
}).catch((error) => { console.error(error); })
});
console.log('Got this from raiseTicket: ' + JSON.stringify(result));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment