Menu condition in Service Portal

cbester
Tera Contributor

I am trying to have a menu item show up only for people in certain groups, which we identify by a parent group field.

In the menu condition field, I can put javascript:(gs.getUser().isMemberOf('groupname')); if I want to only narrow it down to one group. I have written a script to combine the groups in the background into one group as a workaround.

But, what I'd really like is to do something like javascript:(ScriptLibrary.functionname(gs.GetUser())); and create my own script include that returns true or false. Has anyone done this? I have tried having my function just return true or just return false, without any code, and it doesn't show/hide the menu item like it should. So, I'm not sure if it can't be done, or if I'm just not calling the function properly.

I can put in screenshots if that helps. Thanks!

1 ACCEPTED SOLUTION

Geoffrey2
ServiceNow Employee
ServiceNow Employee

If you have created you own Script Include called ScriptLibrary, then the correct way to call it would be:


javascript: new ScriptLibrary().functionname()



You don't really need to pass gs.getUser() as an argument because it's available from with the Script Include.



Your Script Include would look like this:


var ScriptLibrary = Class.create();


ScriptLibrary.prototype = {


      initialize: function() {


      },



      functionname: function() {


              var userObj = gs.getUser();



              return true;


      },



      type: 'ScriptLibrary'


};


View solution in original post

3 REPLIES 3

tanumoy
Tera Guru

Please put the screenshots. It will help.


Geoffrey2
ServiceNow Employee
ServiceNow Employee

If you have created you own Script Include called ScriptLibrary, then the correct way to call it would be:


javascript: new ScriptLibrary().functionname()



You don't really need to pass gs.getUser() as an argument because it's available from with the Script Include.



Your Script Include would look like this:


var ScriptLibrary = Class.create();


ScriptLibrary.prototype = {


      initialize: function() {


      },



      functionname: function() {


              var userObj = gs.getUser();



              return true;


      },



      type: 'ScriptLibrary'


};


Thanks! I couldn't find that syntax anywhere!