- 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-04-2016 05:38 AM
This would work - but you can simplify it a bit like this:
- if (mytable.next()) {
- var groups = mytable.assignment_group.toString(); // Just treat the list as a string, using the 'IN' Operator.
- var memberOf = new GlideRecord('sys_user_grmember');
- memberOf.addQuery('user', currentUser);
- memberOf.addQuery('sys_id', 'IN', groups);
- 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
- }
- }
- 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>