need to remove roles and groups from inactive users

aneelac
Tera Contributor

after update
filter condition
active changes to false


(
function executeRule(previous, current) {

        if (previous.active == true && current.active == 'false') {
            gs.info('Deactivating cleaned up started : ' + current.name);

            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('user', current.sys_id);
            gr.query();
            while (gr.next()) {
                gs.info('deleting record : ' + gr.group.name);
                gr.deleteRecord();

            }

            var gR = new GlideRecord('sys_user_has_role');
            gR.addQuery('user', current.sys_id);
            gR.query();
            while (gR.next()) {
                gs.info('deleting roles: ' + gR.role.name);
                gR.deleteRecord();
            }
        }
   
})(previous, current);
2 REPLIES 2

GlideFather
Tera Patron

Olá @aneelac,

 

are you asking for help or sharing your solution? it's not quite clear :))

If you need help - it might be good to know what is the actual behaviour and what did you explect to happen instead? logs, errors, etc.

 

If sharing your solution, please mark the title with "article", "blog", anything to distinguish it from other questions 

 

Thanks!

 

EDIT: and it seems to be a business rule, correct? but the question is posted under Virtual Agent forum, which doesn't seem to be relevant, or is it?

_____
No AI was used in the writing of this post. Pure #GlideFather only

@GlideFather , i actually posted an accurate logic to remove inactive users from groups and  their roles .