Write a Condition that Hides Items in SP Menu

codechaser
Giga Expert

Looking for a condition that will hide items from displaying in the Service Portal Header Menu.  Right now, I have something that looks like this... GlideSPScriptable.canSeePage("services_status") && gs.getUser()... but need to restrict access, based-on those who are a member of a Department.

Thank you!

1 ACCEPTED SOLUTION

Condition should be GlideSPScriptable.canSeePage("services_status") && new bsu_system_status().getMyDepartmentID()

Use below script

var bsu_system_status = Class.create();
bsu_system_status.prototype = {
initialize: function() {

},

getMyDepartmentID: function() {
if (gs.getUser().getDepartmentID() == 'sysID1' || gs.getUser().getDepartmentID() == 'sysID2' || gs.getUser().getDepartmentID() == 'sysID3')
return true;
else
return false;
},
type: 'bsu_system_status'
};


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

10 REPLIES 10

Can you post me the screenshot how you wrote the script?


Please mark this response as correct or helpful if it assisted you with your question.

I figured-out the problem.  The condition is too long for the input field.  It gets cut-off towards the third department id.  Thoughts?

Ok. In that case you need a script include. call the function with new Scriptname().functionname()

 

So complete function will be GlideSPScriptable.canSeePage("services_status") && new Scriptname().functionname()

The script include should have a function with below script

 

if (gs.getUser().getDepartmentID() == 'sys_id1' || gs.getUser().getDepartmentID() == 'sys_id2' || gs.getUser().getDepartmentID() == 'sys_id3')

return true;

else

return false;


Please mark this response as correct or helpful if it assisted you with your question.

Thanks!  Here's what I currently have:

 

Condition:

 

GlideSPScriptable.canSeePage("services_status") && bsu_service_status().getDepartmentID()

 

Script Include: 

 

var bsu_system_status = Class.create();
bsu_system_status.prototype = {
initialize: function() {
if (gs.getUser().getDepartmentID() == 'sysID1' || gs.getUser().getDepartmentID() == 'sysID2' || gs.getUser().getDepartmentID() == 'sysID3')
return true;
else
return false;
},
type: 'bsu_system_status'
};

 

SysID's are being replaced with actual departments.  However, it does not work.  Suggestions?

Condition should be GlideSPScriptable.canSeePage("services_status") && new bsu_system_status().getMyDepartmentID()

Use below script

var bsu_system_status = Class.create();
bsu_system_status.prototype = {
initialize: function() {

},

getMyDepartmentID: function() {
if (gs.getUser().getDepartmentID() == 'sysID1' || gs.getUser().getDepartmentID() == 'sysID2' || gs.getUser().getDepartmentID() == 'sysID3')
return true;
else
return false;
},
type: 'bsu_system_status'
};


Please mark this response as correct or helpful if it assisted you with your question.