Rejecting a Major Incident Candidate via API

rainsOfSign
Kilo Contributor

Hi Folks,

 

I'm looking for a way to reject major incident candidates via API. The context is, I have an automation that creates P1 incidents. P1 incidents are automatically proposed as a major incident. So, I would like the automation to also reject the proposal. I tried to set the major_incident_state field to 'rejected' while also writing a work_note, but all this did was post the work note. Any assistance (not AI generated please) would be appreciated!

1 ACCEPTED SOLUTION

rainsOfSign
Kilo Contributor

For future people searching for the answer to this question, this is the scripted REST endpoint I ended up writing. You just give an incident number and some notes in the URL params. 

 
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

	var incidentNumber = request.queryParams.incidentid;
	var notes = request.queryParams.notes;

    if (!incidentNumber) {
        response.setStatus(400);
        return {
            success: false,
            error: "Missing required parameter: incidentid"
        };
    }

	if (!notes) {
        response.setStatus(400);
        return {
            success: false,
            error: "Missing required parameter: notes"
        };
    }

    var gr = new GlideRecord('incident');
    gr.addQuery('number', incidentNumber);
    gr.query();

    if (!gr.next()) {
        response.setStatus(404);
        return {
            success: false,
            error: "Incident not found"
        };
    }

	if (notes instanceof Array) {
		notes = notes.join(" ");
	} else {
		notes = String(notes);
	}


	gr.major_incident_state = new sn_major_inc_mgmt.MajorIncidentTriggerRules().MAJOR_INCIDENT_STATE.REJECTED;
	gr.work_notes = notes;
	gr.update();
	
    return {
        success: true,
        sys_id: gr.getUniqueValue(),
        number: gr.getValue('number'),
        short_description: gr.getValue('short_description'),
        state: gr.getDisplayValue('state'),
        priority: gr.getDisplayValue('priority')
    };
	

})(request, response);

View solution in original post

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @rainsOfSign 

 

Create a Scripted Rest API for it.

 

Sample code you will get from this post : take the code logic which is written for UI ACtion.

Reject Major Candidate ui action 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

This did help me reach a solution, so thank you, but I'm not going to accept it as a solution since it wasn't, itself, a solution.

rainsOfSign
Kilo Contributor

For future people searching for the answer to this question, this is the scripted REST endpoint I ended up writing. You just give an incident number and some notes in the URL params. 

 
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

	var incidentNumber = request.queryParams.incidentid;
	var notes = request.queryParams.notes;

    if (!incidentNumber) {
        response.setStatus(400);
        return {
            success: false,
            error: "Missing required parameter: incidentid"
        };
    }

	if (!notes) {
        response.setStatus(400);
        return {
            success: false,
            error: "Missing required parameter: notes"
        };
    }

    var gr = new GlideRecord('incident');
    gr.addQuery('number', incidentNumber);
    gr.query();

    if (!gr.next()) {
        response.setStatus(404);
        return {
            success: false,
            error: "Incident not found"
        };
    }

	if (notes instanceof Array) {
		notes = notes.join(" ");
	} else {
		notes = String(notes);
	}


	gr.major_incident_state = new sn_major_inc_mgmt.MajorIncidentTriggerRules().MAJOR_INCIDENT_STATE.REJECTED;
	gr.work_notes = notes;
	gr.update();
	
    return {
        success: true,
        sys_id: gr.getUniqueValue(),
        number: gr.getValue('number'),
        short_description: gr.getValue('short_description'),
        state: gr.getDisplayValue('state'),
        priority: gr.getDisplayValue('priority')
    };
	

})(request, response);