Service Portal Menu Item Restricted to Certain Groups Using Client Callable Script Include

neil_b
Tera Guru

Hi,

 

I have a dashboard that I am trying to set the Menu Item visibility of in the Service Portal limited to a few groups of users.

 

I have condition on the Menu Item set to

 

 

gs.getSession().isLoggedIn() && new checkIfGroupMember().verifyMembership();

 

 

 

Here is the script include:

 

 

var checkIfGroupMember = Class.create();
checkIfGroupMember.prototype = {
initialize: function() {},

verifyMembership: function() {
if (gs.getUser().isMemberOf() == 'group_sys_id1' || gs.getUser().isMemberOf() == 'group_sys_id2' || gs.getUser().isMemberOf() == 'group_sys_id3')
return true;
}, else: {
return: false,
},
    type: 'checkIfGroupMember'
};

 

 

This is not working, as any user regardless of group can see the dashboard menu item. Can someone help me where I have gone wrong? I don't know if my script include is incorrect or if my condition is incorrect. 

1 ACCEPTED SOLUTION

neil_b
Tera Guru

I was able to get this working on another post by Brad. My syntax was in fact incorrect. The code to achieve this as follows:

var CheckIfGroupMember = Class.create();
CheckIfGroupMember.prototype = {
    initialize: function() {},

    verifyMembership: function() {
      if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
        return true;
    } else {
        return false;
    }
},
    type: 'CheckIfGroupMember'
};

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@neil_b 

you were using wrong syntax for isMemberOf

use this

var checkIfGroupMember = Class.create();
checkIfGroupMember.prototype = {
    initialize: function() {},

    verifyMembership: function() {
        if (gs.getUser().isMemberOf('group_sys_id1') || gs.getUser().isMemberOf('group_sys_id2') || gs.getUser().isMemberOf('group_sys_id3'))
            return true;
    },
    else: {
        return: false,
    },
    type: 'checkIfGroupMember'
};

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar thank you for the suggestion. I have updated my code as you recommended and it is still not working for me. All users still have access to the dashboard. Is it maybe my menu item condition is incorrect? 

@Ankur Bawiskar changing the code still did not work so if you have any other feedback would be great! Thank you Ankur!

neil_b
Tera Guru

I was able to get this working on another post by Brad. My syntax was in fact incorrect. The code to achieve this as follows:

var CheckIfGroupMember = Class.create();
CheckIfGroupMember.prototype = {
    initialize: function() {},

    verifyMembership: function() {
      if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
        return true;
    } else {
        return false;
    }
},
    type: 'CheckIfGroupMember'
};