delete members from watchlist on INC/RITM table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 05:32 AM
Hi All,
I have 2 business rules that runs on INC/RITM to add watchlist members every time a CI is changed or updated.
The below script queries a rel table and gets the members and adds to the watchlist field.
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(',');
Now the requirement is to also delete the members from watchlist field if any of the users are being deleted from the above custom table. I started with the below Business Rule and stuck with the logic.
(function executeRule(current, previous /*null when async*/ ) {
var table = ["incident", "sc_req_item"];
for (var i = 0; i < table.length; i++) {
var gr = new GlideRecord(table[i]);
gr.addQuery('business_service', current.u_cmdb_ci_service);
gr.query();
while (gr.next()) {
//gr.deleteRecord();
}
}
})(current, previous);
Need help with the same.
TIA.
@Tai Vu @Runjay Patel @Uncle Rob @Brad Bowman @Community Alums
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 05:39 AM
watch_list is a glide_list, not a table, so the aim here isn't to "delete records"
You need to build the watch list as you want, and then over-write the previous value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:36 AM
Hi Rob,
Thanks for the reply can I get to see any example that I can follow please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:10 AM
Hi @DPrasna ,
If you wanna make watch list empty and then add the new members in it then use below script.
var table = ["incident", "sc_req_item"];
for (var i = 0; i < table.length; i++) {
var gr = new GlideRecord(table[i]);
gr.addQuery('business_service', current.u_cmdb_ci_service);
gr.query();
while (gr.next()) {
gr.watch_list = ''; // Set the watch_list field to empty
gr.update();
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:35 AM
Hi Runjay, thanks for the reply how do I do it as I have 2 different business rules for adding the members