"gs.getUser().isMemberOf('Group_name') " is not working in UI script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 11:05 PM
Hi All,
I want to show i icon in list only for one group members but it is not working. I'm writing below UI script , i icon in list should be visible to "SCS Leaderboard Group" group members and it should be hidden to others,
(function() {
addAfterPageLoadedEvent(function() {
if (window.location.href.indexOf('u_dashboard_metrics_new_list') != -1) {
if (gs.getUser().isMemberOf('SCS Leaderboard Group')) {
// if (g_user.isMemberOf('SCS Leaderboard Group')) {
// $j('a[class="btn btn-icon table-btn-lg icon-info list_popup"').each(function() {
// $j(this).show();
// });
} else {
//hideRefIcons();
$j('a[class="btn btn-icon table-btn-lg icon-info list_popup"').each(function() {
$j(this).css("display", "none");
});
}
}
});
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 06:07 AM
Hi,
how and in whose session the script include is being triggered
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 09:40 PM
Hi,
The script include is being triggered by an event that is created by a Business Rule.
The script creates incidents based on data in a table. And there in the incident, I have to populate the caller field based on the currently logged-in user.
My guess: I guess that the script is being executed at ServiceNow's servers and at that end the user is "system" with all the permissions. And thus getUserName() function returns me system everytime.
In UI Action it works as expected but in the script include it is not.
Note: I am using the Orlando dev instance. Default session when we first log in.
Kindly provide a good alternative or any solution to this.
Thanks,
Kaushal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 12:53 AM
Hi Payal ,
Also, Instead of giving group name give that group's sys_id .
hope this helps !
Best Regards,
Apeksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 02:10 AM
Hi Apeksha,
FYI; gs.getUser().isMemberOf() works for both group name and group sys_id
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 03:16 AM
ok sir