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

Hi Sanvi,



Thank you for the clarification. The script is very similar. Just change the condition to "State | is | Resolved". To prevent triggering, add inc.setWorkflow(false);.



I will assume you already have a notification set up for when the parent (in this case problem) becomes resolved. If not, refer here: Email Notifications - ServiceNow Wiki



Name: Remove parent problem from child incidents


Table: Problem


When: after


Update: true


Insert: true


Advanced: true


Condition: State | is | Resolved


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.setWorkflow(false);


                  inc.update();


        }



})(current, previous);