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

Narendra Kota
Mega Sage

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.

This display the message but state still changes to Review and close UI appears.

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 

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

}