diff --git a/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ClientScript.js b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ClientScript.js new file mode 100644 index 0000000000..43aba52642 --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ClientScript.js @@ -0,0 +1,16 @@ +function onChange(control, oldValue, newValue, isLoading) { +if (isLoading || !newValue) return; + +// GlideAjax call to fetch department leads +var ga = new GlideAjax('WatchListHelper'); +ga.addParam('sysparm_name', 'getWatchListByCaller'); +ga.addParam('sysparm_caller', newValue); +ga.getXMLAnswer(function(answer) { +if (answer) { +// answer is comma separated list of sys_ids +var currentWatchList = g_form.getValue('watch_list'); +var combined = currentWatchList ? currentWatchList + ',' + answer : answer; +g_form.setValue('watch_list', combined); +} +}); +} diff --git a/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/README.md b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/README.md new file mode 100644 index 0000000000..a7416e7a7c --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/README.md @@ -0,0 +1,15 @@ + +Auto-Add Watch List Based on Caller Department + +//Use Case : + +Automatically adds relevant users to the Watch List field when a Caller is selected on Incident. +Keep department leads or stakeholders automatically informed. + +//Logic: + +Client Script runs onChange of the Caller field. +Calls a Client callable Script Include ('WatchListHelper) via GlideAjax. +Script Include fetches Department manager +Adds their sys_id to the Watch List field. +Prevents duplicates by appending to existing watch list values. diff --git a/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ScriptInclude.js b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ScriptInclude.js new file mode 100644 index 0000000000..01b1504358 --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ScriptInclude.js @@ -0,0 +1,21 @@ +var WatchListHelper = Class.create(); +WatchListHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { + +getWatchListByCaller: function() { +var callerId = this.getParameter('sysparm_caller'); +var watchListSysIds = []; +var userGR = new GlideRecord('sys_user'); +if (userGR.get(callerId) && userGR.department) { +// Fetch department managers +var dept = new GlideRecord('cmn_department'); +if (dept.get(userGR.department)) { +if (dept.manager) + watchListSysIds.push(dept.manager.sys_id.toString()); +} +} +// Return as comma separated string +return watchListSysIds.join(','); +}, + +type: 'WatchListHelper' +});