Cannot update problem state from Assess to Closed via API

ClémentN
Tera Contributor

Hello everyone,

I'm currently having troubles with problem management. I'm using the Table API to update problems. While I didn't have any issue to change the state from New to Assess, I am now stuck trying to move it from the Assess state.

 

I tried PUT/PATCH methods

PUT https://INSTANCE/api/now/table/problem/PROBLEMID

{
    "state": "107",
    "resolution_code": "canceled",
    "close_notes": "My close notes",
    "closed_by": "admin"
}

 but it still stays at state "102" (Assess). In the UI, I can change the state from Assess to Closed without any issue. I inspected the calls and it calls the xmlhttp.do endpoint with the same params as before (without closed_by).

ClmentN_0-1734518976771.png

Do you know what I am doing wrong ?

 

Thanks in advance !

Clément

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ClémentN 

 

Are you able to move the PRB from Assess to Close manually? Please check if any parameter is mandatory to close the prb and if is it missing in the API.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG 

Thanks a lot for your answer. In the UI, yes I can set my problem from Assess to Closed status (by clicking "Cancel" for instance). I checked the fields and no mandatory fields are asked in the UI when I do that. I compared two payloads : one with an already cancelled problem and one with an assessed problem. state, problem_state, resolution_code, close_notes, closed_by and closed_at were the only fields that were different. I tried to provide everything in the payload but still, no change.

Hi @ClémentN 

 

Not sure, what went wrong, but can you check Assess UI action which setting the state to cancel.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,

So i looked into the Assess and Cancel UI Actions.

The assess just calls the onAssess function which basically sets the state

ProblemModalUIHelpers.onAssess = function() {
	var view = g_form.getViewName();
	if (!g_form.hasField("state")) {
		getMessage('Cannot assess the Problem as \'State\' is not visible', function(msg) {
			g_form.addErrorMessage(msg);
		});
		return false;
	}

	g_form.setValue('state', g_scratchpad.STATE.ASSESS);
	if (g_form.mandatoryCheck()) {
		g_form.save();
		return;
	}

	g_form.clearMessages();
	var ob = new ProblemModalUIHelpers();
	var formValues = {
		state: g_scratchpad.STATE.ASSESS
	};
	ob.openModal('assess_dialog_form_view', getMessage('Assess'), 850, formValues, "move_to_assess"); // The Modal has also been used in the Business Rule <Update Problem State to Assess>
};

The Cancel function calls the problem_Cancel function which sets the state and resolution_code, nothing more.

ProblemModalUIHelpers.problem_Cancel = function() {
	if (!g_form.hasField("state") || !g_form.hasField("resolution_code")) {
		getMessage('Cannot Cancel the Problem as atleast one of the following fields are not visible: \'State\' \'Resolution code\'', function(msg) {
			g_form.addErrorMessage(msg);
		});
		return false;
	}

	var sysId = g_form.getUniqueValue();
	g_form.setValue("state", g_scratchpad.STATE.CLOSED);
	g_form.setValue("resolution_code", g_scratchpad.RESOLUTION_CODES.CANCELED);
	if (g_form.mandatoryCheck()) {
		g_form.save();
		return;
	}

	g_form.clearMessages();
	var formValues = {
		state: g_scratchpad.STATE.CLOSED,
		resolution_code: g_scratchpad.RESOLUTION_CODES.CANCELED
	};
	var ob = new ProblemModalUIHelpers();
	ob.openModal("cancel_dialog_form_view", getMessage('Cancel'), 850, formValues, "cancel_problem");
};

I provide the same parameters to cancel my problem which is why I'm a bit confused on why it is not working.