Not updating multiple child incidents

R Charan C
Tera Expert

I'm syncing the parent and child incidents states in extended incident table.
When updating parent1 incident state from InProgress to new, Only Child 1 is changing the state and other child(Child 2) incident state are still in InProgress.

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


    var child_inc = new GlideRecord('incident');
    //  var child_inc = new GlideRecord('extended_incident'); //extended incident table
    child_inc.addQuery('parent_incident', current.sys_id);
    child_inc.query();
    while (child_inc.next()) {
        child_inc.state = current.state;
        child_inc.hold_reason = current.hold_reason;
        if (current.state == 7 || current.state == 8) { //close or canceled
            if (child_inc.close_notes == "") {
                child_inc.close_notes = current.close_notes;
            }
            if (child_inc.close_code == "") {
                child_inc.close_code = current.close_code;
            }

        }

        child_inc.update();
    }




1 REPLY 1

Bert_c1
Kilo Patron

HI @R Charan C 

 

You update the function code with:

 

 

 

 

 

    var child_inc = new GlideRecord('incident');
    //  var child_inc = new GlideRecord('extended_incident'); //extended incident table
    child_inc.addQuery('parent_incident', current.sys_id);
    child_inc.query();
	gs.info("childIncidentsBusinessRule: Found " + child_inc.getRowCount() " child incidents for " + current.number);
    while (child_inc.next()) {
        child_inc.state = current.state;
        child_inc.hold_reason = current.hold_reason;
		gs.info("childIncidentsBusinessRule: Set child_inc: " + child_inc.number + " state: " + current.state " hold_reason: " + current.hold_reason);
        if (current.state == 7 || current.state ==   { //close or canceled
			gs.info("childIncidentsBusinessRule: Set child_inc: " + child_inc.number + " close_notes: " + current.close_notes " close_code: " + current.close_code);
            if (child_inc.close_notes == "") {
                child_inc.close_notes = current.close_notes;
            }
            if (child_inc.close_code == "") {
                child_inc.close_code = current.close_code;
            }

        }

        child_inc.update();
    }

 

 

 

 

 

Test, then check Script Log Statements, with "message", "starts with", "childIncidentsBusinessRule" to see what is going on. And please note, the code you have doesn't have the last "}". for the function definition. And for some reason, when I past the modified code, this post is messing up the line:

if (current.state == 7 || current.state == 😎 { //close or canceled

I see a smiley face where "8" should be.