Incident creation from Webhook Alerts

Senthil19
Kilo Contributor

I followed the instructions provide in the link below to create a Webhook and sucessfully posted an Alert to the system logs .

https://community.servicenow.com/community?id=community_blog&sys_id=886d2a29dbd0dbc01dcaf3231f9619b0

How do i create an incident for the messages /Alerts received through the webhook.

 

Thanks

Senthil

 

 

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Senthil,

In the scripted API that you created as part of the instructions in that blog... instead of doing a log entry, you actually can create the incident.

How?

It's very simple... just include something like the following before or after where you do the log entry...

var grIncident = new GlideRecord('incident');

grIncident.initialize();

grIncident.short_description = 'Incident created from WebHook';

grIncident.description = request.body.dataString;

//the above is just an example. you can parse the request body and fill up the various incident fields depending on the data that you have in your payload

grIncident.insert();

//and Voila! your Incident is created

 

Thanks,

Berny

 

View solution in original post

8 REPLIES 8

bernyalvarado
Mega Sage

Hi Senthil,

In the scripted API that you created as part of the instructions in that blog... instead of doing a log entry, you actually can create the incident.

How?

It's very simple... just include something like the following before or after where you do the log entry...

var grIncident = new GlideRecord('incident');

grIncident.initialize();

grIncident.short_description = 'Incident created from WebHook';

grIncident.description = request.body.dataString;

//the above is just an example. you can parse the request body and fill up the various incident fields depending on the data that you have in your payload

grIncident.insert();

//and Voila! your Incident is created

 

Thanks,

Berny

 

bernyalvarado
Mega Sage

Hi Senthil,

Perhaps to elaborate... you can use pathParams and queryParams to parse / pull the specific attributes of the request payload.

Thanks,

Berny

 

source: https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_reference/ScriptableServiceRequest/concept/c_ScriptableServiceRequest.html?cshalt=yes

RESTAPIRequest - pathParams

The path parameters passed in the request URI.

Field
NameTypeDescription
pathParamsObjectThe path parameters as a script object. Available path parameters depend on the web service configuration.

In this example, the scripted REST API endpoint follows this format: https://instance.service-now.com/api/now/myservice/{tableName}/{id}. The request being processed uses this URL:https://instance.service-now.com/api/now/myservice/myApp_table/1234.

var pathParams = request.pathParams; 
var tableName = pathParams.tableName; //‘myApp_table’ 
var id = pathParams.id; //‘1234’

RESTAPIRequest - queryParams

The query parameters from the web service request.

Field
NameTypeDescription
queryParamsObjectThe query parameters from the web service request.

In this example, the request being processed uses this URL: https://<instance_rest_endpoint>?active=false&name=now. Note the active and name parameters.

var queryParams = request.queryParams; 
var isActiveQuery = queryParams.active; //false 
var nameQueryVal = queryParams.name; //‘now’

bernyalvarado
Mega Sage

I hope this helps Senthil!! Have a great day! 🙂

Senthil19
Kilo Contributor

Berny,

Thanks a lot for the help and your time .

I will try out the instructions provided and keep you posted on the outcome .

Senthil