- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2024 01:42 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2024 05:02 PM
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.
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....
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
My first For Each is simple. Just a For Each entry in the incident's Watch List.
Since the For Each is getting a user reference each time, lets ask if that user is active.
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.
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!
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.
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.
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2024 01:54 PM
That's interesting.
I did a test in our instances using an existing incident, I've added an active user and then I deactivate this user.
Went back to the incident in the other tab and refreshed the page, user removed from watch list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2024 05:56 AM
It might not be visible, but check XML on the record. The sys_id of the user will still be there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2024 05:55 AM
There are many benefits for considering the flow designer alternative to scheduled job.
https://youtu.be/6NgUwujWGFA