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

Remove Roles From a Group

Surbhi16
Tera Contributor

HI, 

How can we remove role from a group using script?

Is there any way we can delete any role from a group based on user input?

Regards,

Surbhi

17 REPLIES 17

Chaitanya Redd1
Tera Guru

Hi Surbhi,

 

Please try below code.

var role = new GlideRecord('sys_group_has_role');
role.addQuery('group', current.sys_id);
role.addQuery('role', '<ROLE_SYS_ID>');
role.query();
while(role.next())
{


role.deleteRecord();
}

 

Regards,

Chaitanya

Anil Lande
Kilo Patron

Hi,

Yes, we can do that, you can use script logic suggested by Chaitanya.

Can you please share what exactly you want to achieve? Also check the possibilities using no code (FLOW) configurations.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

Above Script which is suggested by Chaitanya is not working out for me, My requirement is suppose we have a group--SRM Support which have 5 different roles and based on end user one of the role should be removed. 

# I cant use No code here, i need script to execute

How can we delete it using script?

Are you trying through background script or fix script