when a user is inactive, user should be removed from the report shared by the user

Sadashiva Das1
Tera Contributor

when a user is inactive, user should be removed from the report shared by the user 

Please suggest any BR and Scheduled Job

 

2 ACCEPTED SOLUTIONS

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Sadashiva Das1 ,

Please use this script it will give you the required results

 

var report = new GlideRecord('sys_report_users_groups');

report.addEncodedQuery('user_id.active=false');

report.query();

while(report.next()){

report.user_id=''

report.update()

}

Please mark my answer as correct if it helps.
BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

View solution in original post

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Sadashiva Das1 ,

You can writedown below BR on sys_user table

GunjanKiratkar_0-1669009151870.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var reportShare = new GlideRecord("sys_report_users_groups");
    reportShare.addQuery("user_id", current.sys_id);
    reportShare.query();
    if (reportShare.next()) {
        reportShare.deleteMultiple();
    }


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

4 REPLIES 4

SapAuddy
Giga Expert

Hi Sadashiva,
It is recommended to control user access to reports via Roles and for scheduled reports via Groups.
For removal of 'inactive' user(s) from Group(s), use a scheduled job or BR to remove group membership.

 

Thanks, Saptarshi

Saptarshi A

Some reports are shared individually to many users . need to remove one of those .

 

Please suggest ,

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Sadashiva Das1 ,

Please use this script it will give you the required results

 

var report = new GlideRecord('sys_report_users_groups');

report.addEncodedQuery('user_id.active=false');

report.query();

while(report.next()){

report.user_id=''

report.update()

}

Please mark my answer as correct if it helps.
BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Sadashiva Das1 ,

You can writedown below BR on sys_user table

GunjanKiratkar_0-1669009151870.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var reportShare = new GlideRecord("sys_report_users_groups");
    reportShare.addQuery("user_id", current.sys_id);
    reportShare.query();
    if (reportShare.next()) {
        reportShare.deleteMultiple();
    }


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy