Need help troubleshooting client callable script include

neil_b
Tera Guru

I have condition on the Menu Item set to the following:

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

The intent of this condition is to check if the user is Logged In and is part of a specific group.

 

Here is the client callable script include:

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'
};

 

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

Brad Bowman
Kilo Patron
Kilo Patron

You might need to pass the current user as an argument in the Script Include.  Where exactly are you using this?  Is your Script Include in the same scope as whatever is calling it?  Your Script Include is not truly Client callable as the extended AjaxProcessor was not added to the beginning, which happens when the box is clicked after the script exists, but it doesn't need to be Client callable in this case - that's only necessary for GlideAjax calls from a client script.

 

Your if statement is not formatted correctly.  Change it to:

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

You may need to add some log lines to confirm this is running, based on the call in the condition, and confirm the value of gs.getUser().  Do you really need the first part of the Condition - is it possible for users in your environment to not be logged in, yet still be members of groups?

View solution in original post

20 REPLIES 20

Gopi Naik1
Kilo Sage

Hi @neil_b ,

 

Please try below:

 

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'
};

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

Hi @Gopi Naik1 I tried your code but I'm getting incorrect syntax on lines 10 and 11.

incorrect syntax.png

Please add complete screenshot of your script include.

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

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'
};