I want to Reopen an incident using Scripted Rest API Method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:23 AM - edited 11-23-2022 05:24 AM
Hello,
I have one requirement on scripted REST API,
I have one resolved incident here i need to Reopen that incident using scripted Rest API, so how can i achieve this
can anyone give me the suggestion to get the solution
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 06:01 AM
Hello,
You can just update the incident sate back to 2. it is same as you would be updating any other field in Incident form using scripted rest api.
So if you provide them a scripted api endpoint, they just need to provide the number or sysid of the icnident they want to reopen and then you can just reopen the incident by gliding and updating the state
Example:-
Sample JSON request:
{
"incidentNumber": "INC000124",
}
Scripted REST API Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body.dataString;
var parser = new global.JSON();
var parsedData = parser.decode(requestBody);
var number = parsedData.incidentNumber
var rec = new GlideRecord('incident');
rec.addQuery('number',number);
rec.query();
if(rec.next()){
rec.state=2;
rec.incident_state=2;
rec.update();
var responseBody = {};
responseBody.incNumber = number;
responseBody.status = "Success";
response.setBody(responseBody);
}
else{
var responseBodyFailure = {};
responseBodyFailure.status = "Failure";
response.setBody(responseBodyFailure);
}
})(request, response);
Please mark my answer as correct based on Impact.