How to make Ctask closure mandatory before moving review state in change request

jituksingh
Kilo Guru

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

1 ACCEPTED SOLUTION

Bridget6
Kilo Expert

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.

find_real_file.png

 

 find_real_file.png

 

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);

}

 

View solution in original post

7 REPLIES 7

Hi Bridget,

your suggestion helped me last time. Now I want that even if a manual change task is added this functionality work same way with manual change task also. Can you suggest a solution for this also.

 

Regards,

Jitendra Singh

Hi - this may be what you're looking for.

We have a before update business rule set as follows with the script below on the Advanced tab

find_real_file.png

 

Advanced tab

Condition: new ChangeRequest(current).changesToClosed()

Script

(function executeRule(current, previous /*null when async*/) {


if (hasOpenTasks(current.sys_id)) {
gs.addErrorMessage(gs.getMessage('Unable to close the Change request as there are open Change tasks'));
current.setAbortAction(true);
//action.setRedirectURL(current);
}
function hasOpenTasks(sys_id)
{
var cTaskAgg = new GlideAggregate('change_task');
cTaskAgg.addQuery('change_request', sys_id);
cTaskAgg.addQuery('u_bypass_close_check','=','false');
cTaskAgg.addActiveQuery();
cTaskAgg.addAggregate("COUNT");

cTaskAgg.query();
if (cTaskAgg.next())
return (cTaskAgg.getAggregate("COUNT") > 0);

return false;
}

})(current, previous);

Hi Bridget,

 

I tried your solution (actually both of them) but they dont work for me and I dont know why...I am still able to move to review phase, but I am not able to move to close/cancel state till the tasks are closed or cancelled, could you help me? Could be problem with this because of new releases of SMnow?