diff --git a/Server-Side Components/Business Rules/Update Incident State To Closed/readme.md b/Server-Side Components/Business Rules/Update Incident State To Closed/readme.md new file mode 100644 index 0000000000..2dcffe73e6 --- /dev/null +++ b/Server-Side Components/Business Rules/Update Incident State To Closed/readme.md @@ -0,0 +1 @@ +To close a parent record when its children are closed in ServiceNow, create a Business Rule or Flow Designer on the child table. This rule should trigger when a child record's state changes to "closed," check if all related child records are closed, and then update the parent record's state accordingly. diff --git a/Server-Side Components/Business Rules/Update Incident State To Closed/script.js b/Server-Side Components/Business Rules/Update Incident State To Closed/script.js new file mode 100644 index 0000000000..b4c1a854a8 --- /dev/null +++ b/Server-Side Components/Business Rules/Update Incident State To Closed/script.js @@ -0,0 +1,20 @@ +var pSysId = 'sys_id'; +var child= new GlideRecord('incident'); +child.addQuery('parent_incident',pSysId); +child.query(); +var count=0; +while(child.next()){ + + if(child.state!=7) + { +count =1; + gs.print("your child incident is not there or is not yet closed"); + } +} +if(count==0){ + child.parent_incident.state=7; + child.parent_incident.close_code='Duplicate'; +child.parent_incident.close_notes="done"; +child.parent_incident.update(); +gs.print("hello" + child.parent_incident.number); +}