- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
I got a request to hide a couple of modules from non-managers. Here is how I did it:
var GMF_ClientUserUtil = Class.create();
GMF_ClientUserUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Given a user sys_id get the manager
isManager: function(userId) {
var returnVal;
try{
//if the param is null, use the current user's ID
if(JSUtil.nil(userId)){
userId = gs.getUserID();
}
var util = new GMF_UserUtil();
returnVal = util.isManager(userId);
}catch(e){
gs.logError(e.message,'SI:GMF_ClientUserUtil->isManager()');
}
return returnVal;
}
});
var GMF_UserUtil = Class.create();
GMF_UserUtil.prototype = {
initialize: function () {
},
//Check to see if the user is anyone's manager (only looks at active users)
isManager: function(userId){
var gr = new GlideAggregate('sys_user');
gr.addActiveQuery();
gr.addQuery('manager', userId);
gr.addAggregate('COUNT');
gr.query();
gr.next();
if( gr.getAggregate('COUNT') > 0 ){
return true;
}
return false;
},
type: 'GMF_UserUtil'
}
I created a global UI Script: (The syntax highlighter gave me > 10 minutes worth of grief when trying to format this so I gave up.)
document.observe("dom:loaded", function() { | ||
var ga = new GlideAjax('GMF_ClientUserUtil'); | ||
ga.addParam('sysparm_name', 'isManager'); | ||
ga.getXML(isManagerCallback); |
});
function isManagerCallback(response){ |
var answer = response.responseXML.documentElement.getAttribute("answer");
//Hide the "Incident - Manager" module
if (answer == 'false' && parent.frames[0].document.getElementById('module.b2ca14786f319500b8d923fc5d3ee4c7')) {
parent.frames[0].document.getElementById('module.b2ca14786f319500b8d923fc5d3ee4c7').style.display = 'none'; |
}
//Hide the "Request Items - Manager" module
if (answer == 'false' && parent.frames[0].document.getElementById('module.d335eefd6f1f5900aaaa23fc5d3ee403')) {
parent.frames[0].document.getElementById('module.d335eefd6f1f5900aaaa23fc5d3ee403').style.display = 'none'; |
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.