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.

Close Case - Stay on the Case

MStritt
Tera Guru

Currently, when I Close a Case by clicking on the Close Case button, I'm redirected to the previous place I accessed that Case from. For example, if I'm in Case list view and click on a Case from there, it opens the Case. When I close it, I'm returned back to the list view. If I'm already  in a Case and I search for a different Case from the global search window, it opens the Case. When I close it, it returns me back to the previous Case I was in when I searched on the Case to close. I want to stay on the Case I closed, and not be redirected to the previous location I was at when I accessed the Case.

2 ACCEPTED SOLUTIONS

can you try this?

var grCT = new GlideRecord("sn_customerservice_task");
grCT.addQuery("parent", current.sys_id);
grCT.addQuery("active", true);
grCT.query();
if (grCT.next()) {
gs.addErrorMessage("You cannot Resolve or Close a Case with open Tasks");
//current.setAbortAction(true);
} else {
new global.StateFlow().processFlow(current, 'd8069501c33231005f76b2c712d3aead', 'manual');

//if current user is the case caller, redirect the user to survey
if (current.contact == gs.getUserID()) {
//The executed triggerCondition sys_id
var TriggerConditionId = "97a9bec1c37231005b2c7bfaa2d3ae33";
//The assessment sys_id in the executed triggerCondition
var assessmentType = "a0dfbc85c33231001b757bfaa2d3aee7";
var assessmentSysId;
var gr = new GlideRecord("asmt_assessment_instance");
gr.addQuery("trigger_condition", TriggerConditionId);
gr.addQuery("user", current.contact);
gr.addQuery("state", "ready");
gr.addQuery("trigger_id", current.sys_id);
gr.query();
if (gr.next()) {
assessmentSysId = gr.getValue("sys_id");
if (!gs.nil(assessmentSysId)) {
var url = '/assessment_take2.do?sysparm_assessable_type=' + assessmentType + '&sysparm_assessable_sysid=' + assessmentSysId;
action.setRedirectURL(url);
}
}
} else {
// Stay on the same page after closing the case
action.setRedirectURL(current);
}
}

View solution in original post

Also, what did you add to the code I provided?

 

Just?:

 

} else {
// Stay on the same page after closing the case
action.setRedirectURL(current);
}
}

View solution in original post

10 REPLIES 10

ar grCT = new GlideRecord("sn_customerservice_task");
	grCT.addQuery("parent", current.sys_id);
	grCT.addQuery("active", true);
	grCT.query();
	if(grCT.next()) {
		gs.addErrorMessage("You cannot Resolve or Close a Case with open Tasks");
		//current.setAbortAction(true);
	} else {
		new global.StateFlow().processFlow(current, 'd8069501c33231005f76b2c712d3aead', 'manual');
//if current user is the case caller, redirect the user to survey
if(current.contact == gs.getUserID()){
	//The executed triggerCondition sys_id
	var TriggerConditionId = "97a9bec1c37231005b2c7bfaa2d3ae33";
	//The assessment sys_id in the executed triggerCondition
	var assessmentType = "a0dfbc85c33231001b757bfaa2d3aee7";
	var assessmentSysId;
	var gr = new GlideRecord("asmt_assessment_instance");
	gr.addQuery("trigger_condition", TriggerConditionId);
	gr.addQuery("user", current.contact);
	gr.addQuery("state","ready");
	gr.addQuery("trigger_id",current.sys_id);
	gr.query();
	if(gr.next()){
		assessmentSysId = gr.getValue("sys_id");
		if(!gs.nil(assessmentSysId)) {
			var url = '/assessment_take2.do?sysparm_assessable_type='+assessmentType+'&sysparm_assessable_sysid='+assessmentSysId;
			action.setRedirectURL(url);
		}
	}
}
	}

This line should be at the end of the script.

action.setRedirectURL(current);

Please mark this response as correct or helpful if it assisted you with your question.

I did update the last line with action.setRedirectURL(current);

but it didn't work. I'm seeing the same behavior. The screenshot is after I changed it back.

can you try this?

var grCT = new GlideRecord("sn_customerservice_task");
grCT.addQuery("parent", current.sys_id);
grCT.addQuery("active", true);
grCT.query();
if (grCT.next()) {
gs.addErrorMessage("You cannot Resolve or Close a Case with open Tasks");
//current.setAbortAction(true);
} else {
new global.StateFlow().processFlow(current, 'd8069501c33231005f76b2c712d3aead', 'manual');

//if current user is the case caller, redirect the user to survey
if (current.contact == gs.getUserID()) {
//The executed triggerCondition sys_id
var TriggerConditionId = "97a9bec1c37231005b2c7bfaa2d3ae33";
//The assessment sys_id in the executed triggerCondition
var assessmentType = "a0dfbc85c33231001b757bfaa2d3aee7";
var assessmentSysId;
var gr = new GlideRecord("asmt_assessment_instance");
gr.addQuery("trigger_condition", TriggerConditionId);
gr.addQuery("user", current.contact);
gr.addQuery("state", "ready");
gr.addQuery("trigger_id", current.sys_id);
gr.query();
if (gr.next()) {
assessmentSysId = gr.getValue("sys_id");
if (!gs.nil(assessmentSysId)) {
var url = '/assessment_take2.do?sysparm_assessable_type=' + assessmentType + '&sysparm_assessable_sysid=' + assessmentSysId;
action.setRedirectURL(url);
}
}
} else {
// Stay on the same page after closing the case
action.setRedirectURL(current);
}
}

Yes, this worked.

 

We have a field on our Case called Product Name (u_product_name). Is it possible to update/change this code, to only stay on the Case when closed, if the Product Name is a specific value? For example, Product Name on the Case is 'Widget'. When clicking on the 'Close Case' button and Product Name is 'Widget', then stay on the Case when it's closed. If not, then continue the current behavior when the Case is closed.