- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 12:54 AM - edited 03-13-2025 03:57 AM
Hello team,
I have active schedule email reports and now i want to check all active reports recipients and if any of the user under schedule report is inactive I need to remove them.
What is the best approach to do that because manually open each schedule report and check whether user is active or not involves lot of manual efforts.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 05:57 AM
Not sure why you are tagging people in your question. It would be better to send a DM if you only want a response from any of them.
Related to your question: the names are set in a list field, which means it has a list of comma separated sysids of those users. You will need to create a fix script that does a look up to all these users and removes the inactive ones.
Something like this:
(function executeFixScript() {
var grScheduledReport = new GlideRecord('sysauto_report');
grScheduledReport.addQuery('active', true);
grScheduledReport.query();
while (grScheduledReport.next()) {
var userList = grScheduledReport.getValue('user_list');
if (!userList) continue;
var userArray = userList.split(',');
var activeUsers = [];
for (var i = 0; i < userArray.length; i++) {
var userSysId = userArray[i].trim();
var grUser = new GlideRecord('sys_user');
if (grUser.get(userSysId) && grUser.getValue('active') === 'true') {
activeUsers.push(userSysId);
}
}
var updatedUserList = activeUsers.join(',');
grScheduledReport.setValue('user_list', updatedUserList);
grScheduledReport.update();
}
})();
But it would be good to also create a flow or BR to check for the same when a user is inactivated to prevent you having to do this multiple times per year.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 05:57 AM
Not sure why you are tagging people in your question. It would be better to send a DM if you only want a response from any of them.
Related to your question: the names are set in a list field, which means it has a list of comma separated sysids of those users. You will need to create a fix script that does a look up to all these users and removes the inactive ones.
Something like this:
(function executeFixScript() {
var grScheduledReport = new GlideRecord('sysauto_report');
grScheduledReport.addQuery('active', true);
grScheduledReport.query();
while (grScheduledReport.next()) {
var userList = grScheduledReport.getValue('user_list');
if (!userList) continue;
var userArray = userList.split(',');
var activeUsers = [];
for (var i = 0; i < userArray.length; i++) {
var userSysId = userArray[i].trim();
var grUser = new GlideRecord('sys_user');
if (grUser.get(userSysId) && grUser.getValue('active') === 'true') {
activeUsers.push(userSysId);
}
}
var updatedUserList = activeUsers.join(',');
grScheduledReport.setValue('user_list', updatedUserList);
grScheduledReport.update();
}
})();
But it would be good to also create a flow or BR to check for the same when a user is inactivated to prevent you having to do this multiple times per year.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 06:29 PM
Thank you so much Mark its really helpful.