The CreatorCon Call for Content is officially open! Get started here.

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

Hi Anil,

I have tested the flow and the script you suggested

find_real_file.png

 

find_real_file.png

 

find_real_file.png

My adding role to a group part is working but removing part are not working.

Regards,

Surabhi

Chaitanya Redd1
Tera Guru

Hi,

you can try below one.

var gr = new GlideRecord('sys_user_role');
gr.addQuery('name','LIKE',vaInputs.group_name); 
gr.query();
while (gr.next()) { 
    var gr2 = new GlideRecord('sys_user_has_role');
    gr2.addEncodedQuery(role.name=vaInputs.group_role_to_be_removed);
    gr2.deleteRecord();
}

Hi,

Its not working

Regards,

Surabhi

 

Anitha H V
Giga Expert

Hi Surbhi,

You can use the code that is mentioned in the below community link.

Remove Role : https://community.servicenow.com/community?id=community_question&sys_id=9c39364edb0d4c181cd8a345ca9619db

Just take this as a reference and then code it as per your need.

  • Mark my Answer as CORRECT and HELPFUL if it helps

Thanks & Regards,

Anitha H V

Hi Anitha,

Its not working for me, I already refered to that link.

Regards,

Surbhi