- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2016 05:58 PM
I am working on a project where we want a specific function to happen. Either a ticket is assigned to a user, or it is assigned to user group(s). The group in the table references the User Groups table and is a LIST date type. I want to check where user is in the list of assigned_to users, or where the user is in any of the groups.
So if the ticket was only assigned to one user group, then this would be fairly simple. But it is effectively a list compared to a list. Any guidance would be appreciated. This is on a custom table in a custom application.
var gr = new GlideRecord('');
gr.addQuery('assigned_to', 'CONTAINS', gs.getUser().getID());
gr.query();
I know to add an or condition but dont really understand what to put in the condition.
gr.addQuery('assigned_to', 'CONTAINS', gs.getUser().getID()).addOrCondition('assignment_group', ' ', ' ');
Any help would be appreciated. Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2016 07:08 AM
This was my solution:
- <j:set var="jvar_groups" value="${gr.assignment_group.toString().split(',')}" />
- <j:forEach var="jvar_group" items="${jvar_groups}">
- <div>${jvar_group}</div>
- <j:if test="${gs.getUser().isMemberOf('${jvar_group}')}">
- <g:macro_invoke macro="x_sample_macro" />
- <j:break />
- </j:if>
- </j:forEach>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2016 07:16 PM
Hi Logan,
Do you want to check if the caller is part of any group?..Can you please elaborate further your req with a example so that we can help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2016 07:22 PM
Yeah no problem. So in my custom table, the row assignment_group is a reference to the sys_user_group table with data type of list. I want to see if out of all the groups that a user is in, if that user has a group that is in the list on the table. The user in question would be the user object found by gs.getUser().

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2016 07:25 PM
Hi Logan,
You can query against the table sys_user_grmember by passing the sys_id of the user as a addQuery to return true or false.
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2016 11:30 PM
Hi Logan,
Building on Pradeep's suggestion, I think I would do something like this (if I'm following you correctly). For fun, I made a new table called MyTable and made a list reference to the Groups table called assignment_group on it.
isMember('MYT0001001');
function isMember(ticketNumber) {
var currentUser = gs.getUser().getID();
var mytable = new GlideRecord('u_mytable'); // Custom table called MyTable that has a reference list to sys_user_groups
mytable.addQuery('number', ticketNumber);
mytable.query();
if (mytable.next()) {
var groups = mytable.assignment_group.split(","); // Split the list string of sys_ids into an array
var encodedQuery = ""; // Build encoded query string to use on sys_user_grmember table
for (i = 0; i < groups.length; i++) {
if (i == 0) {
encodedQuery += 'group=' + groups[i];
} else {
encodedQuery += '^ORgroup=' + groups[i];
}
}
var memberOf = new GlideRecord('sys_user_grmember');
memberOf.addQuery('user', currentUser);
memberOf.addEncodedQuery(encodedQuery);
memberOf.query();
if (memberOf.hasNext()) {
return true; // User is a member of one of the groups on the list
} else {
return false; // User is not a member
}
}
}
I haven't tested any of this, but hopefully it helps some what.