I want to Reopen an incident using Scripted Rest API Method

mannu ghangare
Giga Contributor

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

 

 

1 REPLY 1

Saurav11
Kilo Patron
Kilo Patron

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.