I have to remove roles and group when user profile is not active.

niveditakumari
Mega Sage

Hi, 

 

I have to remove roles and group when user profile is not active. 

Can anyone please help me to achieve that. 

 

Regards, 

Nivedita 

 

 

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @niveditakumari roles are always tied to group. There are 2 ways to do this

1. using flow designer , no code required, trigger will be when active is false

 

2. using after update BR,

Cond: active is false

script:

var user = new GlideRecord('sys_user');
user.addQuery('active', false);
user.query();
while (user.next()) {
// Remove groups
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user.sys_id', user.sys_id);
grp.query();
while (grp.next()) {
grp.deleteMultiple();
}
}

Regards
Harish

View solution in original post

5 REPLIES 5

shyamkumar VK
Kilo Patron

@niveditakumari , here is the Solution , First Try in Lower Instance 

 

https://www.servicenow.com/community/developer-forum/how-to-remove-roles-and-groups-for-inactive-use...

 

Regards,

Shyamkumar

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

chetanb
Tera Guru

Harish KM
Kilo Patron
Kilo Patron

Hi @niveditakumari roles are always tied to group. There are 2 ways to do this

1. using flow designer , no code required, trigger will be when active is false

 

2. using after update BR,

Cond: active is false

script:

var user = new GlideRecord('sys_user');
user.addQuery('active', false);
user.query();
while (user.next()) {
// Remove groups
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user.sys_id', user.sys_id);
grp.query();
while (grp.next()) {
grp.deleteMultiple();
}
}

Regards
Harish

HI @Harish KM

 

Thank you so much for your help. 

It is working now. 

 

Regards, 

Nivedita