I Need the all records which is have the users in active in list collector
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 12:50 AM
Hi team,
I have one requirement. I have list collector filed (Users) in "sysauto_report" table. I need get list of records which is users are inactive in list collector filed .
Can you you help me on this
Thank you in advance
Siva
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 04:49 AM
Depending on how you want the output, this could work for you?
//Fetch the reports we want to check
var fetchReportsQuery = function() {
var scheduledReportsGR = new GlideRecord('sysauto_report');
scheduledReportsGR.addNotNullQuery('user_list');
scheduledReportsGR.query();
return scheduledReportsGR;
};
//A memoized function to check user active status
//Users could appear multiple times in different reports
//So we memoize to prevent duplicate glide record queries
var isUserActive = (function(userSysId) {
var cache = {};
return function(userSysId) {
if (cache.hasOwnProperty(userSysId))
return cache[userSysId];
var userGR = new GlideRecord('sys_user');
if (userGR.get(userSysId)) {
cache[userSysId] = JSUtil.getBooleanValue(userGR, 'active');
return cache[userSysId];
}
};
})();
var resultObj = {};
var reportsGR = fetchReportsQuery();
while (reportsGR.next()) {
var hasInactiveUsers = false;
var reportUsers = reportsGR.getValue('user_list');
var reportUsersArray = reportUsers.split(',');
var userDetails = reportUsersArray.map(function(user){
var result = {};
result[user] = isUserActive(user);
if(result[user] == false)
hasInactiveUsers = true;
return result;
});
resultObj[reportsGR.getUniqueValue()] = {
'users' : userDetails,
'hasInactive' : hasInactiveUsers
}
}
//The result is an object of reports, users in them, their status,etc.
gs.info(JSON.stringify(resultObj , null ,4))
It'll output something like the below which is the report, the status of each user, and then a flag to tell you if the report has inactive users.
{
"300b89131b119e10298ac841604bcbe8": {
"users": [
{
"25a2ef811b7746104c55ed3b234bcb52": true
},
{
"443193dcd7011200f2d224837e61037d": false
}
],
"hasInactive": true
}
}