- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 08:52 AM
Hi,
I don't want to move change state to review until all Ctask are closed which were opened on Implementation. Currently it allow to use Review UI action and Ctasks get closed incomplete. I want to abort the change movement until the chnage tasks are closed and pop up an alert if review Action pressed without closing the ctasks.
Thanks and Regards,
Jitendra singh
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:00 AM
The review ui action in our change request has the following conditions set along with the script below. This stops the move to review state until the tasks are closed.
function moveToReview(){
//Check for remaining tasks before moving to Review
g_form.clearMessages();
//Type appropriate comment here, and begin script below
var gr = new GlideRecord("change_task");
gr.addQuery("change_request","=",g_form.getUniqueValue());
gr.addQuery("state","<","3"); //anything less than 3 is not closed
gr.setLimit(1);
gr.query(); //purposefully not async
if(gr.next()) {
g_form.addErrorMessage("Cannot move to Review state while Change Tasks are open");
return false;
}
else {
//no remaining tasks, move to Review
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_new");
});
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 09:05 AM
You can write a business rule on Change Request table,
When: before insert and update.
Filter Conditions: State changes to Review
script:
var gr = new GlideRecord('change_task');
var str = 'stateNOT IN4,3,7';
gr.addQuery('change_request',current.sys_id);
gr.addEncodedQuery(str);
gr.query();
if(gr.next())
{
current.setAbortAction(true);
gs.addInfoMessage('Please close the Change tasks');
}
Hope this helps.
Mark helpful or correct based on impact.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 09:20 AM
This display the message but state still changes to Review and close UI appears.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 10:35 AM
If the infomessage displays and still state changing to Review, I believe "Review" UI action might be conflicting with this business rule.
verify the UI action or post the script here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:00 AM
The review ui action in our change request has the following conditions set along with the script below. This stops the move to review state until the tasks are closed.
function moveToReview(){
//Check for remaining tasks before moving to Review
g_form.clearMessages();
//Type appropriate comment here, and begin script below
var gr = new GlideRecord("change_task");
gr.addQuery("change_request","=",g_form.getUniqueValue());
gr.addQuery("state","<","3"); //anything less than 3 is not closed
gr.setLimit(1);
gr.query(); //purposefully not async
if(gr.next()) {
g_form.addErrorMessage("Cannot move to Review state while Change Tasks are open");
return false;
}
else {
//no remaining tasks, move to Review
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_new");
});
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}