The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Need to remove inactive users from active reports

maddamsetti
Tera Contributor

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.

 

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

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

View solution in original post

2 REPLIES 2

Mark Manders
Mega Patron

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

Thank you so much Mark its really helpful.