Update group name based on the group added in variable using workflow activity

ss123
Tera Contributor

Hi Everyone,

I have this requirement wherein I need to automate the changing of a group name based on what group name is defined in a variable. I need this in a workflow activity. Below is the scenario:

Scenario 1: A user will submit a catalog item, and add the group name in a Reference field to be updated. Input the New Group Name in a single line text field. Once the form is submitted, it will automatically change the Group Name mentioned on the reference field with the new Group Name indicated in another field.

Is that possible? Can you guys helm ne on this? 🙂

Thank you in advance!

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi you can use below run script activity for the same

Script:

var getGroupName = current.variables.variablename; // reference type var of group

var newGroupName = current.variables.variablename; // new group name

var grp = new GlideRecord('sys_user_group');

grp.addQuery('sys_id',getGroupName );

grp.query();

if(grp.next())

{

grp.name = newGroupName ;

}

grp.update();

Regards
Harish

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Sabrina Salazar 

you can get started from your side

But sample script might look like this in workflow run script

var groupSysId = current.variables.groupVariable; // name of variable which refers Group table

var newGroup = current.variables.groupName; // name of variable which holds new group name

var grp = new GlideRecord('sys_user_group');
if(grp.get(groupSysId)){
	grp.name = newGroup;
	grp.update();
}

Regards
Ankur

 

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

@Sabrina Salazar 

The response marked as correct should have the update() line within the if

Regards
Ankur

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

Thanks @Ankur Bawiskar for the help 🙂