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.

Create incident with Scripted REST API

sarabjeet
Giga Expert

Hi,

Can you please tell me how to create incident with Scripted REST API?

 

1 ACCEPTED SOLUTION

sarabjeet
Giga Expert

hi,

I tried and created this simple Scripted API. It is working for me.

You can add fields as per your requirement.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var responseBody = {};
var event = request.body.data;
var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = event.caller;
inc.short_description = event.Summary;
inc.insert();
responseBody.message = "Incident created.";
responseBody.incidentnumber = inc.number;
response.setBody(responseBody);

Output:

find_real_file.png

Incident created :

find_real_file.png

View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

This Scripted REST API training on the developer site will walk you through creating a SRAPI to interact with a custom app table. I would run through this training and then apply what you've learned to creating an incident.

Hi Brad,

Thanks for your inputs.

Regards,

Sarabjeet

sarabjeet
Giga Expert

hi,

I tried and created this simple Scripted API. It is working for me.

You can add fields as per your requirement.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var responseBody = {};
var event = request.body.data;
var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = event.caller;
inc.short_description = event.Summary;
inc.insert();
responseBody.message = "Incident created.";
responseBody.incidentnumber = inc.number;
response.setBody(responseBody);

Output:

find_real_file.png

Incident created :

find_real_file.png