- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 06:07 PM
Hi,
I hope someone is able to assist me. I am very new to ServiceNow and I have been tasked with the orchestration part because of my skills with powershell.
I am task with setting up a termination process. I have been able to use many of the activities in my workflow that allow updates to Active Directory, my final task to this process is to create catalog task tickets for each group that a user belongs to. The CATCH is that we only need certain groups to have catalog task tickets created.
Allow me to explain:
We have many groups that are assigned to each user, the naming convention for the ones that I need to create catalog task tickets for all start with _ACCESS (see example below).
_ACCESS DocMagic
_ACCESS New Hope
These are just an example of a couple of groups.
How can I get just those groups (that start with _ACCESS) and create a catalog task ticket for each one?
I searched around and can't seem to find anything close to what I need. Any help would be appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 07:44 PM
Okay, this should work in a workflow 'Run Script' activity.
var userID = current.variable_pool.employee_name;
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user', userID);
grp.addQuery('group.name', 'STARTSWITH', '_ACCESS');
grp.query();
while (grp.next()) {
// Create 'sc_task' for each group found
var tsk = new GlideRecord('sc_task');
tsk.initialize();
tsk.request_item = current.sys_id;
tsk.short_description = 'Offboard ' + grp.user.getDisplayValue() + ' from ' + grp.group.getDisplayValue() + '.';
tsk.assignment_group = grp.getValue(group);
tsk.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2018 10:13 AM
Mark,
Thank you so much! It worked!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 06:53 PM
Hi,
First of all, the relationship between users and groups is stored in a many to many table named sys_user_grmember, I recommend you get familiar with it, you can query this table to get all the groups to which a user belongs and also query for the group name.
The code could be something like this, also I recommend you take a look at "Fix Scripts" in ServiceNow as a perfect place to test this code:
var groupMembershipGR = new GlideRecord('sys_user_grmember');
groupMembershipGR.addQuery("user","46d44a23a9fe19810012d100cca80666"); //you can use the sys_id of the user record
groupMembershipGR.addQuery("group.name","STARTSWITH","_ACCESS");
groupMembershipGR.query();
while(groupMembershipGR.next()){
//create a task for each group
gs.print("Create a catalog task for group "+groupMembershipGR.group.name+", ");
}
Hope this helps,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 07:43 PM
Thank you, I didn't know about the Fix Scripts. I will give it a try.