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

How to Replace the 'workspace_user' role on all groups that have it with the 'agent_workspace_user' role.

HARI KISHAN GVS
Mega Sage

Hi Team,

Please let me know how to acheive this.

i have around 120 groups that have workspace_user role.

Now, I want to replace workspace_user role to agent_workspace_user role in all the groups.

i tried with transform map with Group set as colasee but sys_group_has_role record is not updating.

can anyone please provide a sample fix script to acheive this.

Thanks in advance.

Hari kishan.

1 ACCEPTED SOLUTION

Hi Sumanth,

Just small Correction to the code..

Need to replace sys_user_group to sys_group_has_role  in line 1.

Thank you,

Hari Kishan.

View solution in original post

8 REPLIES 8

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You can try with below fix script.

var gr = new GlideRecord("sys_user_group");
		gr.addQuery("role", "sysid of existing role"); // give old role sysid
		gr.query();
		while(gr.next()) {

			var gr1 = new GlideRecord("sys_group_has_role");
				gr1.initialize();
				gr1.group = gr.group;
                                gr1.role = "sysid of new role"; //give sysid of your new role
				gr1.insert();
                       gr.deleteRecord();
			
		}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

@HARI KISHAN GVS 

Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth

Hi Sumanth,

Just small Correction to the code..

Need to replace sys_user_group to sys_group_has_role  in line 1.

Thank you,

Hari Kishan.

@HARI KISHAN GVS 

Did you mistakenly marked your own response as correct?

The script I shared already had the correct solution.

Would you mind marking appropriate response as correct?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader