Remove inactive users from watchlist

ValeriaS
Tera Contributor

I am trying to make a scheduled job that runs once a day. The purpose of this scheduled job is to look into all active incidents which contain at least one person in the watchlist and remove any inactive users from the watchlist. Can anyone help with this?

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

Ok, I built this out for the practice. Before we start, please be aware that Glide_List fields are simply strings that store comma separated sys_ids.  Observe.

UncleRob_3-1732840983015.png

You'll also need to define two flow variables
- NewWatchList:  this will store our valid user sys_id's to pump back into the watch list
- RemovedNames:  This will store a string of friendly user names that we removed from the watch list.  This isn't required, just going to make your Incident work notes more informative.

 

Here's the flow....

UncleRob_10-1732841893317.png

 

My first look up was just to a single sample Incident.  You'd want to look up a set of records then do a For Each to loop through them.  Anyway... here's what my sample incident started with.  Akila P is inactive

UncleRob_2-1732840920279.png

My first For Each is simple. Just a For Each entry in the incident's Watch List.  

UncleRob_5-1732841151492.png

Since the For Each is getting a user reference each time, lets ask if that user is active.

UncleRob_6-1732841244495.png

If the user IS active, lets pump their sys_id to flow variable NewWatchList, which is a string that will contain comma separated sys_ids.  Don't copy this verbatim as the code will change based on the node you're pulling from and yours might not match mine.  If you've never scripted values in flow you type in fd_data. and the system helps you fill in the rest.  Its how you access your Data Picker via script.  Super noice.
This code says "combine the NewWatchList variable with whatever its previous value was, plus a comma, plus the sys_id of the user I'm currently on in the For Each.

UncleRob_7-1732841327761.png

So if the user is NOT active, lets add their name to flow variable RemovedNames.  Notice this time I'm not getting the user's sys_id, I'm getting their name!

UncleRob_8-1732841529457.png

Now that we've looped through all the users in the watch list, lets update the Incident.  But we only need to update IF there were users to remove.  We'll know if the cleanse was unnecessary if RemovedNames is not empty.

UncleRob_11-1732841988528.png

Now we just update the watch list (with NewWatchList) and then add a charming little work note to inform people which users have been removed from the watch list.

 

UncleRob_9-1732841656450.png

 

BOOM!!   Cleansed watch list and informative work note if users were removed.  (forgive me I was too lazy to hyper optimize the grammar of the work note update.)

UncleRob_12-1732842107018.png

 

 

 

 

View solution in original post

12 REPLIES 12

Luiz Lucena
Mega Sage

Hi @ValeriaS 

 

That should have something out of box as they automatically remove assignee from Assigned To field.

 

I'll look further to that and reply here.

@Luiz Lucena - It does not happen OOB.  Not even for assignment.  The sys_id is still in the reference field, its just not getting the display because the user is inactive.

Hi @Uncle Rob , 

 

Then I'll double check what we have done because we have something doing this.

 

Thanks 

Funny thing is... I think you can't select an inactive user for Assigned_To, but you CAN put an inactive user into watch list.