- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:03 AM - edited 02-22-2024 08:47 AM
Hey,
I created a script on ui action such that when the button is clicked, it calls a function that checks if change record has any change task open or not. If change has open task it should show error message.
The function moveToImplement() doesn't seem to execute at all.
We have client checkbox checked on ui action. But when we click it, the page doesn't even reload. Basically nothing happens.
Also if the change has no change task, then also it doesn't seem to work.
function moveToImplement(){
var gr_tsk = new GlideRecord('change_task');
gr_tsk.addEncodedQuery'(state=1^change_request.sys_id==current.sys_id'); // state = 1 is open state of change task and change request sys id associayed to change task is same that of current record sysid.
gr_tsk.query();
if(gr_tsk.hasNext()){
alert("Cannot close change record. There are change tasks are associayed");
//current.setAbortAction(true);
}
else{
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "review");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_review");
});
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 04:31 AM
use action.setRedirectURL(current)
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 01:41 AM - edited 02-23-2024 03:46 AM
This is the BR I am using but now the issue is it stops the UI action but it doesn't redirect user to updated change record. It is displaying the error message as well, but state get changed to "next state". User has to reload the page to see the ui action didn't process and state is still the current state.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("change_task");
gs.log("business rule triggered");
gr.addActiveQuery();
gr.addQuery('change_request', current.sys_id);
gr.query();
if(gr.next()){
gs.addErrorMessage("can't process");
//gr.setValue('state', -1 );
current.setAbortAction(true);
gs.setRedirect('https://instance-name/change_request.do?sys_id='+current.sys_id);
gs.log("if condition works");
}
// Add your code here
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 04:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 04:48 AM
still need to reload the page. I guess abort action and redirect does not work together