- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2014 01:04 PM
I'm trying to hide certain variables on a Catalog Item (actually part of a Variable Set) based on Group Membership (and roles).
My use case is basically hiding a checkbox if the user does not have either the 'itil' role, or is a member of the 'Human Resources' group (no role).
I don't seem to be able to do this via a UI Policy, because I only want to show/hide a single variable of a variable set.
So, I settled on a Display Business Rule and a Client Script combo in order to achieve it (open to better solutions); however, I can't get this combination to work.
Display Business Rule:
userIsMemberHR(); function userIsMemberHR() { g_scratchpad.isMemberOfHR = gs.getUser().isMemberOf('Human Resources'); }
Client Script:
function onLoad() { var itil_usr = g_user.hasRole('itil'); if ((!itil_usr) && (!g_scratchpad.isMemberOfHR)) { // 'itil' role or 'Human Resources' group var val = g_form.getValue("variables.offboard_immediately"); g_form.setDisplay('variables.offboard_immediately',false); } }
Before adding the group membership portion, the role membership was working fine with just the Client Script.
Appreciate your assistance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2016 07:33 AM
Hello,
I was looking for info on this and tried your example, this works in geneva P7.
This is the onDisplay BR:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.isMemberOfITSAPECC = gs.getUser().isMemberOf('IT SAP ECC');
g_scratchpad.myTest = "hola";
})(current, previous);
And this is the CS:
function onLoad() {
//Type appropriate comment here, and begin script below
var myVariablesAreReadOnly = true;
if((g_scratchpad.isMemberOfITSAPECC && g_form.getValue("state") == 9) || g_user.hasRole("admin")){
myVariablesAreReadOnly = false;
}
g_form.setReadOnly("variables.u_sap_short_description", myVariablesAreReadOnly);
g_form.setReadOnly("variables.u_sap_testers_approvals", myVariablesAreReadOnly);
g_form.setReadOnly("variables.u_sap_business_approvals", myVariablesAreReadOnly);
}
Just in case anyone else is trying this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2014 05:04 PM
Totally agree, I have those all taken care of for 'itil' users. Works like a charm.
It's got to be relatively easy, as you can show/hide whole Catalog Items based on Group Membership, but the UI doesn't allow that to extend easily to individual variables on a Catalog Item.
I've even gotten it to work on the Catalog Item Form, but not on the CMS Catalog Item itself, which leads me to think I've got my Display Business Rule on the wrong table (currently on sc_cat_item). I don't see it execute when I Debug Business Rules.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2016 07:33 AM
Hello,
I was looking for info on this and tried your example, this works in geneva P7.
This is the onDisplay BR:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.isMemberOfITSAPECC = gs.getUser().isMemberOf('IT SAP ECC');
g_scratchpad.myTest = "hola";
})(current, previous);
And this is the CS:
function onLoad() {
//Type appropriate comment here, and begin script below
var myVariablesAreReadOnly = true;
if((g_scratchpad.isMemberOfITSAPECC && g_form.getValue("state") == 9) || g_user.hasRole("admin")){
myVariablesAreReadOnly = false;
}
g_form.setReadOnly("variables.u_sap_short_description", myVariablesAreReadOnly);
g_form.setReadOnly("variables.u_sap_testers_approvals", myVariablesAreReadOnly);
g_form.setReadOnly("variables.u_sap_business_approvals", myVariablesAreReadOnly);
}
Just in case anyone else is trying this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2016 09:17 AM
Just as an aside...Nestor's answer works, but ultimately, the solution that is the most portable would be:
- Create roles and assign them to the Groups in question.
- Utilize the built-in functionality to "Exclude" Catalog Variables based on Role (that Jim Coyne mentioned). This is fully supported by ServiceNow and would survive future upgrades.
Thanks for the answer Nestor!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2021 10:26 AM
In which table is the display business rule written?
Does not seem to work for me