Prevent incident from getting closed until the associated change is closed

harsha328
Tera Contributor

If a change is created from an incident using the 'create Change' UI action on incident form, the incident from which the change is created can usually be resolved/closed without closing the change. How can this be prevented?

The incident should not be allowed to be closed/resolved unless the Change created from it is closed.

Any help is really appreciated

Thanks,

Harsha

1 ACCEPTED SOLUTION

Abhinandan Pati
Giga Guru

Hi Harsha,



It would be better if you can hide the 'Closed' option from incident state field if change is not in closed state. Or else you can abort update action by writing before update business rule on incident table which should trigger whenever state changes to closed state. Here is the sample code snippet



Condition: current.state.changesTo('Closed state choice value')



Script:



var flag=false;


var chg=new GlideRecord('change_request');


chg.addQuery('parent.sys_id',current.sys_id);


chg.query();



while(chg.next()){


if(chg.state!='closed'){


flag=true;


break;


}


}


if(flag==true){


current.addErrorMessage('Can't update incident state');


current.setAbortAction(true);


}



Thanks


Abhinandan


View solution in original post

3 REPLIES 3

Abhinandan Pati
Giga Guru

Hi Harsha,



It would be better if you can hide the 'Closed' option from incident state field if change is not in closed state. Or else you can abort update action by writing before update business rule on incident table which should trigger whenever state changes to closed state. Here is the sample code snippet



Condition: current.state.changesTo('Closed state choice value')



Script:



var flag=false;


var chg=new GlideRecord('change_request');


chg.addQuery('parent.sys_id',current.sys_id);


chg.query();



while(chg.next()){


if(chg.state!='closed'){


flag=true;


break;


}


}


if(flag==true){


current.addErrorMessage('Can't update incident state');


current.setAbortAction(true);


}



Thanks


Abhinandan


Mike Allen
Mega Sage

You can do a onSubmit client script



if(g_form.getValue('state') == 7){


        var state = g_form.getReference('change', changeState);


}



function changeState(state){


        if(state != 4){


                  alert('You must close the associated change before closing the incident');


                  return false;


        }


]


Midhun1
Giga Guru

Hi,



Write a business rule on incident table take values of problem from related list and glide record the change table check the status and prevent it and add info message.