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

SanjivMeher
Mega Patron
Mega Patron

In you Close Case UI action, you need to add another line of code to stay on the same page.

action.setRedirectURL(current);


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

Hi Sanjiv!

 

It's currently showing as:

action.setRedirectURL(url);
 
Do you know what url is referring to in this context?

I just updated (url) to (current), and I'm seeing the same behavior.

From: action.setRedirectURL(url);

To: action.setRedirectURL(current);

Can you please share the whole script in your UI action?


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