Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function onChange(control, oldValue, newValue, isLoading) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • When a caller is changed or cleared before save, the old user department manager should be removed from watchlist.

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);
}
});
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Department table doesn't have manager field OOTB.

watchListSysIds.push(dept.manager.sys_id.toString());
}
}
// Return as comma separated string
return watchListSysIds.join(',');
},

type: 'WatchListHelper'
});
Loading