- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2024 01:14 PM
I have a requirement to make the UI action visible only when logged in users group is part of certain groups. I created a system property which stores the sys_ids of the groups and want to call this system property in a script Include which I can add on a UI Action.
Note: The reason I am not adding the condition on UI action is it has a character limit of 40 char on UI action condition and I have other conditions as well along with group visibility it was not fitting all the conditions here.
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2024 08:14 PM
Whereas that may "work", it is far from being efficient. You are looping through and making a query for each Group sys_id. A better script would be something like this:
(function() {
var user = gs.getUserID();
var ids = gs.getProperty("whatever_name_it _is");
var ga = new GlideAggregate("sys_user_grmember");
ga.addEncodedQuery("group.sys_idIN" + ids + "^user=" + user);
ga.addAggregate('COUNT');
ga.query();
while(ga.next()){
gs.print(ga.getAggregate("COUNT"));
gs.print(ga.getAggregate("COUNT") > 0); //is the User in any of the Groups?
}
})();
One query to get the number of records returned. The result would be:
But again, would not do it this way. Look at my response to the original post on what I believe is a much more elegant solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2024 06:08 PM
Hello @Varun Sai ,
I did the same except incident logic inclusion in the script and got successful results as below:
1. Created system property with group's syd_id's.
2. Created background script to check if current logged in user is part of the group which is mentioned in the system property. I got result as "True".
You can use this script in your script include and get results successful.
Please DO NOT forget to mark this solution as correct and Helpful if it satisfied your query. This enhances the interest to provide solutions on community.
Thank You,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2024 08:14 PM
Whereas that may "work", it is far from being efficient. You are looping through and making a query for each Group sys_id. A better script would be something like this:
(function() {
var user = gs.getUserID();
var ids = gs.getProperty("whatever_name_it _is");
var ga = new GlideAggregate("sys_user_grmember");
ga.addEncodedQuery("group.sys_idIN" + ids + "^user=" + user);
ga.addAggregate('COUNT');
ga.query();
while(ga.next()){
gs.print(ga.getAggregate("COUNT"));
gs.print(ga.getAggregate("COUNT") > 0); //is the User in any of the Groups?
}
})();
One query to get the number of records returned. The result would be:
But again, would not do it this way. Look at my response to the original post on what I believe is a much more elegant solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2024 07:07 AM
Hi @Jim Coyne ,
I was able to get the results successfully in background script. But, when I try to implement in the script include with other queries I am not getting the results. I may be going wrong somewhere.
getCheckCondition: function(curRec){ var user = gs.getUserID(); var ids = gs.getProperty("sn_user.groups"); var ga = new GlideAggregate("sys_user_grmember"); ga.addEncodedQuery("group.sys_idIN" + ids + "^user=" + user); ga.addAggregate('COUNT'); ga.query(); if(ga.next()){
var grIncRec = new GlideRecord("incident");
grIncRec.addQuery('sys_id', curRec.sys_id);
grIncRec.query();
if (grIncRec.next()) {
if ((grIncRec.state != '7') && (grIncRec.correlation_id == '') && (grIncRec.correlation_display == '') && (grIncRec.u_transfer_id == false)) {
return true;
}
}
}, })();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2024 06:50 PM
Did you see my other post describing how to do it with a Role instead? That is a much better way of doing it:
- Simple: no code or System Properties to maintain
- easily maintained by simply add/removing the Role to/from Groups
I was just trying to show that the script example was not a good one. I do NOT recommend going this route.