diff --git a/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/README.md b/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/README.md new file mode 100644 index 0000000000..e624b3d709 --- /dev/null +++ b/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/README.md @@ -0,0 +1,2 @@ +Suggests change requests to attach to the incident record based on CI. +Updates work notes with the numbers of change requests that can be relevant for the incident after incident is created. diff --git a/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/script.js b/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/script.js new file mode 100644 index 0000000000..2ba80dc648 --- /dev/null +++ b/Server-Side Components/Business Rules/Add work notes for relevant Change Requests for Incident/script.js @@ -0,0 +1,23 @@ +(function executeRule(current, previous /*null when async*/) { + + // Add your code here + if(current.cmdb_ci){ + var ci = current.cmdb_ci; + + var chng = new GlideRecord('change_request'); + chng.addQuery('cmdb_ci', ci); + chng.addQuery('state', '!=', '3'); + chng.addQuery('state', '!=', '4'); + chng.query(); + + var work_notes = 'Following change requests are associated with same CI. You can attach one of them.\n'; + + while(chng.next()){ + work_notes += chng.number + '\n'; + } + + current.work_notes = work_notes; + current.update(); + } + +})(current, previous);