"gs.getUser().isMemberOf('Group_name') " is not working in UI script

payal1
Kilo Explorer

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");
                });
            }
        }
    });
})();
9 REPLIES 9

Hi,

how and in whose session the script include is being triggered

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Apeksha Joshi
Kilo Guru

Hi Payal ,

Also, Instead of giving group name give that group's sys_id .

hope this helps !

Best Regards,

Apeksha

Hi Apeksha,

FYI; gs.getUser().isMemberOf() works for both group name and group sys_id

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ok sir @Ankur Bawiskar