The Now Platform® Washington DC release is live. Watch now!
‎10-24-2014 12:27 PM
I would like to restrict visibility of an Application Module based on an attribute on the sys_user table, rather than by role.
Is that possible?
I know I could create a new role and assign it to everyone I need to, but I'd prefer to use an existing attribute "u_is_manager" on my sys_user table.
-Rob
Solved! Go to Solution.
‎10-26-2014 03:33 PM
OK here is some example code that may work for you.
if(!gs.hasRole("admin") && gs.getSession().isInteractive() && gs.getUserName() != "guest"){
var qc = current.addQuery('u_visibility', "both");
qc.addOrCondition('u_visibility', '');
if (gs.getImpersonatingUserName() != null) {
gs.getSession().clearClientData('navQuery');
}
var navQuery = gs.getSession().getClientData('navQuery');
if (navQuery == null) {
var isManager = gs.getUser().getRecord().getValue('u_is_manager');
if (!isManager) {
qc.addOrCondition('u_visibility', 'nonmanager');
gs.getSession().putClientData('navQuery', 'nonmanager');
} else {
qc.addOrCondition('u_visibility', 'manager');
gs.getSession().putClientData('navQuery', 'manager');
}
} else {
qc.addOrCondition('u_visibility', navQuery);
}
}
Explanation of the above:
Hopefully this makes sense. Please reply if not as I am happy to answer questions. I am traveling a little this week so my responses could be delayed.
‎10-24-2014 12:33 PM
not sure if that's possible currently ...
‎10-25-2014 03:14 PM
This is definitely possible and something I have done. Unfortunately I don't have time to provide detailed specifics at the moment, but to summarize the solution you utilize a before query business rule on the sys_app_module table. What I had done was created a new field on the sys_app_module table called "Visibility" and had a few choices such A, B, Both. Then in the before query business rule I looked up a value from the user or some other record to know which visibility choice to use and either filtered the modules appropriately.
Here are some example before query business rules:
Useful Task Scripts - ServiceNow Wiki
I will post some example code later.
‎10-26-2014 03:33 PM
OK here is some example code that may work for you.
if(!gs.hasRole("admin") && gs.getSession().isInteractive() && gs.getUserName() != "guest"){
var qc = current.addQuery('u_visibility', "both");
qc.addOrCondition('u_visibility', '');
if (gs.getImpersonatingUserName() != null) {
gs.getSession().clearClientData('navQuery');
}
var navQuery = gs.getSession().getClientData('navQuery');
if (navQuery == null) {
var isManager = gs.getUser().getRecord().getValue('u_is_manager');
if (!isManager) {
qc.addOrCondition('u_visibility', 'nonmanager');
gs.getSession().putClientData('navQuery', 'nonmanager');
} else {
qc.addOrCondition('u_visibility', 'manager');
gs.getSession().putClientData('navQuery', 'manager');
}
} else {
qc.addOrCondition('u_visibility', navQuery);
}
}
Explanation of the above:
Hopefully this makes sense. Please reply if not as I am happy to answer questions. I am traveling a little this week so my responses could be delayed.
‎11-03-2014 05:29 PM
Rob Pickering, curious if the above code addressed your requirement?