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

Hi Ankur,

Both are working but, your solution is time consumig, as i need to put around 120 groups in the Var Str(need to open each group record and copy name of the group and past it in the string). it won't need it in my correct response.

That's why i didn't mark your answer as complete.

Thank you,

Hari Kishan.

Glad that you made it to work.

Looks like you marked your own answer as correct 🙂

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

There is no script required; you can use Update Selected Records on List of sys_group_has_role table and update the role field to new role; It would update for all those groups.

Edit multiple records in a list using an editing form

OR

If you still require fix script then check this

I assume you must be having the names of those 120 groups or sysIds

Update as this

updateRoles();

function updateRoles(){
	try{
		var str = 'Group 1,Group2,Group3'; // give here 
		var gr = new GlideRecord("sys_group_has_role");
		gr.addQuery("group.name", "IN", str);
		gr.addQuery("role.name", "workspace_user");
		gr.query();
		while(gr.next()) {
			gr.setDisplayValue('role','agent_workspace_user');
			gr.update();
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

Regards
Ankur

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

@HARI KISHAN GVS 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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