Automate adding members to group

JLeong
Mega Sage

Hi guys,

Using flow designer, how can I automate the fulfilling of a catalog task that adds users to different groups.

The request contains a list collector of all the groups the user needs to be added.

Below is the flow, I can't seem to select the group when I try to create the record in the sys_user_grmember record.

Thank you in advance.

 

find_real_file.png

1 ACCEPTED SOLUTION

Found out that this feature(For Each Logic on Variables) is still not supported in Flow Designer.

PRB1343826

Alternatively, custom action can be used.

View solution in original post

21 REPLIES 21

Hi Imran, 

Sorry for the delay. We have not rolled this out.

But to start, I created an action called "Create Group":

find_real_file.png

 

and below is the script:

(function execute(inputs, outputs) {

//*** Create group ***//
var grp = new GlideRecord('sys_user_group');
grp.initialize();
grp.name = inputs.name;
grp.manager = inputs.manager;
grp.type = inputs.type;
var groupId = grp.insert();

//*** Add ITIL role to the group *** //
if(groupId){
var grRole = new GlideRecord("sys_group_has_role");
grRole.initialize();
grRole.group = groupId;
grRole.setValue("role","9aaaa632844fa400c50c3aed6c7cc667"); //itil
grRole.setValue("inherits",true);
grRole.insert();

}

// *** Add members *** //
var grmem = new GlideRecord('sys_user_grmember');
var usr = new GlideRecord('sys_user');
usr.addQuery("sys_id","IN",inputs.members);
usr.query();
while(usr.next()){
grmem.initialize();
grmem.group = groupId;
grmem.user = usr.sys_id;
grmem.insert();
}

})(inputs, outputs);

thank you.. will try it out.

Nilanjan1
Mega Sage

Can someone share the output I have been trying to prepare a combination of create a user group which I successfully did but I am not able to add members in the group. I have tried to use a subflow/ action but no go.. I need to close this urgently. Can someone get back to me asap. 

Are you adding a single user to the newly  created group?

If so, just create a record to the sys_user_grmember.

 

Or you can do this....