Add members automatically to watchlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 08:07 AM
Hi All,
The requirement is as follows:
There is a custom table related list on CI - name "u_m2m_from_cmdb_ci_service_watchlist".
So whenever an INC or RITM is updated/ inserted with any of the CI it should pull the watchlist members from the custom table and update the same.
I have below BR written on INC/RITM table so whenever a CI is updated or inserted it adds the watchlist members
(function executeRule(current, previous /*null when async*/ ) {
var user_ids = [];
var grWatchlist = new GlideRecord('u_m2m_from_cmdb_ci_service_watchlist');
grWatchlist.addQuery('u_cmdb_ci_service', current.getValue('business_service'));
grWatchlist.query();
while (grWatchlist.next()) {
user_ids.push(grWatchlist.getValue('u_user'));
}
current.watch_list = user_ids.join(',');
})(current, previous);
However I want the same to happen from the custom table, so whenever a member is added to the custom table "u_m2m_from_cmdb_ci_service_watchlist" it should add the member automatically to the watchlist of INC/RITM how do I do it?
@Ankur Bawiskar @Runjay Patel @Ravi Gaurav @Sandeep Rajput @Dr Atul G- LNG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 08:13 AM
use this in after update BR on custom table
Condition: Watch list changes
script:
(function executeRule(current, previous /*null when async*/ ) {
// Get the CI service from the current record
var ciService = current.u_cmdb_ci_service;
// Get the user ID from the current record
var userId = current.u_user.toString();
// Update watchlist for INC records
var incGr = new GlideRecord('incident');
incGr.addQuery('business_service', ciService);
incGr.query();
while (incGr.next()) {
var watchlist = incGr.watch_list.split(',');
if (watchlist.indexOf(userId) === -1) {
watchlist.push(userId);
incGr.watch_list = watchlist.join(',');
incGr.update();
}
}
// Update watchlist for RITM records
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('business_service', ciService);
ritmGr.query();
while (ritmGr.next()) {
var watchlist1 = ritmGr.watch_list.split(',');
if (watchlist1.indexOf(userId) === -1) {
watchlist1.push(userId);
ritmGr.watch_list = watchlist1.join(',');
ritmGr.update();
}
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 06:49 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 07:00 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 08:20 AM
Hi @DPrasna
Might be helpful
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************