- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 01:57 AM
Hi Arjun,
Can you try the following script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 02:43 AM
Hi Ishan,
Thanks for the help on this,
As I'm new to ServiceNow it will be very helpful if you kindly help with this part of the query,
gr.addEncodedQuery('user='+usr+'^group.name=Director Group');
Regards
Arjun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 03:08 AM
Hi Arjun,
What help do you need from that line of the code ?
If you mean helping you understand - it does the following
The addEncodedQuery basically builds up the filter that you would like to apply on the glide record (table).
the two attributes that you have on the group membership table are
1) user 2) group
you want that the requested for user must be member of a particular group (Director group) and if it is true then return yes
so in this we are building that query
'user=' --> is the attribute on the membership table.
+usr+ --> dynamic value of the requested for user value.
'group.name=Director Group' --> search for the group name value (exact match with Director Group) value.
Thanks
Ishan Parikh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 02:43 AM
Hi
Please try the below script :-
var arr=[];
var usr=current.variables.requested_for;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', usr);
gr.query();
while(gr.next())
{
arr.push(gr.sys_id.toString());
}
for(var j=0;j<arr.length;j++)
{
checkForEveryGroup(arr[j]);
}
function checkForEveryGroup(eachGroup)
{
//here check your condition
//each group has now the groups in which the user is in. It will call this function for every iteration and do you checkinng.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 03:16 PM
Hi
Business Rule *before*
This works perfect for preventing duplicate record entries to the Group Member table (sys_user_grmember)
Remember to add a filter if you are targeting ONLY a specific group.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rec = new GlideRecord('sys_user_grmember');
rec.addEncodedQuery('group.name=your_groupname^active=true');//Action to apply only to members of this group
rec.addQuery('user',current.user);
rec.query();
if(rec.getRowCount() == 1){
gs.addErrorMessage(current.user.getDisplayValue() + " is already high risk asset owner");
current.setAbortAction(true);
}
})(current, previous);