The CreatorCon Call for Content is officially open! Get started here.

Business Rule - Close all Child record when Parent Close

hongsok
Tera Contributor

Dear all,

I have created a business rule to Close all Child Records when Parent is Close but if there is any Open task on the Child record the action will be aborted. It is not working. Could someone help me to take a look?

I would appreciate you help.

______________________________

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

    var gs = new GlideRecord('x_g_afi_mcms_incident_case_task');
    gs.addQuery('parent.parent', current.sys_id);
    gs.query();
    while (gs.next()) {
        if (current.state != 3) {
            gs.addErrorMessage('Cannot close Misconduct case with open Incident case task');
            gs.addInfoMessage(gr.number);
            current.setAbortAction(true); //abort the record
        } else if (current.state == 3) {
            var gr = new GlideRecord('x_g_afi_mcms_incident_case');
            gr.addQuery("parent", current.sys_id);
            gr.query();
            while (gr.next()) {
                gr.status = "close_out";
                gr.update();

            }
        }
    }
})(current, previous);

____________________________________

 

5 REPLIES 5

Hi Hongsok,

Try this.

var chidInc = new GlideRecord('incident');
    chidInc.addQuery('state', 'NOT IN', '6,7,8');
    chidInc.addQuery('parent_incident', current.sys_id);
    chidInc.query();
    if (chidInc.next()) {
        gs.info("###### Found Active Child ######");
        gs.addErrorMessage("A child incident is not resolved/closed. Please close all child incidents before closing parent incident.");
        current.setAbortAction(true);
        var grandChild = new GlideRecord('incident');
        grandChild.addQuery('state', 'NOT IN', '6,7,8');
		grandChild.addQuery('parent_incident', chidInc.getValue('sys_id'));
        grandChild.query();
		if(grandChild.next()){
			current.setAbortAction(true);
		} else{
			current.setAbortAction(true);
		}
    }

 

Refer to this if this doesnt work. Read all comments.

How to make Business Rule prevent parent closure and chekc if child INCs are open


***Mark Correct or Helpful if it helps.***