- 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 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
03-01-2024 04:43 AM
Thankyou for your help and assistance. I was able to resolve it using business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:23 AM
Hi @PriyanshuVerma1 ,
Add single quotes to encoded query
gr_tsk.addEncodedQuery('state=1^change_request.sys_id=' + current.sys_id);
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 09:02 AM
Yeah i corrected that, i noticed it after posting here. But that also didn't work. The query is not getting triggered.
Because even if there no change task open, the implemented button is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:54 PM
There's no addEncodedQuery within GlideRecord in the Client side.
Let try to change your script like below, it should do the trick
function moveToImplement() {
var gr_tsk = new GlideRecord('change_task');
gr_tsk.addQuery('active', true);
gr_tsk.addQuery('change_request', g_form.getUniqueValue());
gr_tsk.query();
if (gr_tsk.hasNext()) {
alert("Cannot close change record. There are change tasks are associayed");
} 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);
}
In the other hand, you can have a business rule to validate existing active change tasks before moving to a new specific state. Then you can just have a simple UI Action to update the state of the change request.
Cheers,
Tai Vu