Automate the adding of users to groups via a request workflow issue

Clinton F
Tera Expert

Hi,

We currently have a automated request to add users to groups. The process is you select the group and the user via the form. When submitted a approval will be sent to the group manager. Once approved the user will be added to the group. This has been working for sometime now but it has failed. 

I think it is because the workflow has to impersonate a account with additional access like a admin. But it has worked in the past. 

This is the code we are using. 

var group = current.variables.add_group;
var user = current.variables.add_member.toString();
var array = user.split(",");

var adminUser = gs.getProperty('qbe.admin_account');            
var originalUser = gs.getSession().impersonate(adminUser);   // elevate priviledges to add roles

//gs.addInfoMessage("Selected users are:" + ' ' + user);

for (var i = 0; i < array.length; i++) {
	var gr_member = new GlideRecord('sys_user_grmember');
	gr_member.initialize();
	gr_member.group = group;
	gr_member.user = array[i].toString();
	gr_member.insert();
}

gs.getSession().impersonate(originalUser);   // return to original session

 If anyone know why this would be please let me know or if there is a better way to do this.

Many thanks
Clinton

1 ACCEPTED SOLUTION

Clinton F
Tera Expert

The fix for this was to add a Timer action to the workflow before my script runs. The activity is then added to the event log which runs as the System, which has all the access needed. 

View solution in original post

5 REPLIES 5

Clinton F
Tera Expert

The fix for this was to add a Timer action to the workflow before my script runs. The activity is then added to the event log which runs as the System, which has all the access needed.