Removing the Parent child relationship when the state of Parent is Resolved

sanvi007
Kilo Explorer

Hi,

How to remove the relationship between parent and child when the state of parent is resolved.

Can anyone help with the script.

5 REPLIES 5

Gurpreet07
Mega Sage

And how would you define a parent, child.       is it incident ,problem, change or a CI . How parent is related to child.


It can be anything. Like incident is parent of problem for example.


Hi Sanvi,



You could do this with an after business rule on the parent table. The condition will watch for active changes to false or state changes to closed (or whatever)



Build a query for all child records where the parent is the current record.


For each record found, clear the parent field.



Example:



Name: Remove parent problem from child incidents


When: after


Update: true


Insert: true


Advanced: true


Condition: Active | changes to | false


Script:


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



        var inc = new GlideRecord('incident');


        inc.addQuery('problem', current.getValue('sys_id'));


        inc.query();



        while (inc.next()) {


                  inc.parent = '';


                  inc.update();


        }



})(current, previous);



Business Rules - ServiceNow Wiki


Business Rules Best Practices - ServiceNow Wiki  


Hi ctomasi,



Here i want to check when the parent state is resolved all the child incidents for that parent should not be anymore related for that parent.


i.e when the state of parent is resolved the notification should be triggered only to the parent none of the child incidents should receive the notifications.