By business rule that adds the Manager of the Caller to the Watchlist when the priority is set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 09:49 PM
Hi,
business rule that adds the Manager of the Caller to the Watchlist when the priority is set to Critical.
Please help me out with the Business rule.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2025 01:18 AM
Hello @kranthi2
Now, in Advanced section tab under script field just populate the below code:
(function executeRule(current, previous /*null when async*/ ) {
// Check if the priority is set to Critical and it has changed
if (current.priority == 1 && current.priority != previous.priority) {
// Get the Caller's manager
var caller = current.caller_id.getRefRecord();
var manager = caller.getValue('manager');
if (manager) {
// Add the manager to the Watchlist
var watchlist = current.watch_list ? current.watch_list.split(',') : [];
if (watchlist.indexOf(manager) == -1) {
watchlist.push(manager);
current.watch_list = watchlist.join(',');
}
}
}
})(current, previous);
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2025 02:47 AM
Hello @kranthi2
To meet the requirement, create an After Insert and After Update Business Rule with the condition set to Priority is Critical.
- Configuration setup:
- Below is the Business Rule script:
(function executeRule(current, previous /*null when async*/) {
// Check if Caller is set and the Priority is Critical (1)
if (current.caller_id && current.priority == 1) {
// Get the Manager of the Caller (assuming 'manager' is a reference field on sys_user)
var manager = current.caller_id.manager;
// Check if the Manager exists
if (manager) {
// Add the Manager to the Watchlist (assuming 'watch_list' is a field that stores user references)
var watchList = current.watch_list; // This assumes watch_list is a reference field
if (watchList) {
// Check if Manager is already in the Watchlist
if (!watchList.includes(manager.sys_id)) {
current.watch_list = watchList + ',' + manager.sys_id; // Add Manager's sys_id to Watchlist
}
} else {
// If Watchlist is empty, just set the Manager's sys_id
current.watch_list = manager.sys_id;
}
// Update the incident record
current.update();
}
}
gs.addInfoMessage("manager updated");
})(current, previous);
Result:
Once the form is saved with Priority set to Critical (1), the Business Rule (BR) is triggered, and the Watchlist is populated with the Caller’s Manager.
Note: I tested this in my PDI (Personal Developer Instance), and it worked as expected.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 02:39 AM
Hi @Juhi Poddar
It works, thanks.