- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:41 AM
I am very new to SN and JS. I am trying to understand how to add multiple groups to the client and server scripts below. The script is used to limit who can open a priority 1 incident.
What is the syntax or proper method to add a second (or third group) group using this method (e.g. add a "mytestgroup2" group)? The easiest method I can think is to add a second business rule, but I am sure it is easier than that.
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
//g_form.addInfoMessage('Scratchpad : ' + g_scratchpad.isMember);
//Called the g_scratchpad.isMember funtion within the Display Business Rule
if (g_scratchpad.isMember == true)
{
g_form.removeOption('impact', '1');
g_form.removeOption('urgency', '1');
}
}
Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.isMember = gs.getUser().isMemberOf('mytestgroup1');
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 07:09 AM
You can just add or condition in the BR
if(gs.getUser().isMemberOf('mytestgroup1') || gs.getUser().isMemberOf('mytestgroup2') || gs.getUser().isMemberOf('mytestgroup3')){
g_scratchpad.isMember=true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:50 AM
Zeller,
IF I understand correctly you want to hide the priority 1 value for some groups ...
Well, then who can see it ? When should it be shown ? hide ? I mean should be it hidden for some roles ? groups ? users ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:56 AM
Yes, I only want to hide the priority 1 value from groups mytestgroup1, mytestgroup2, and possibly mytestgroup3. It should be shown by default. The above scripts hide p1 values from one group, but I want to add more groups to the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:59 AM
For me you don't need to create a BR and a client script, a client script only is enough :
You can put it in onLoad. This script will check if the user logged in is memberOg a particular group and will hide the Priority 1 choice.
Here is a sample of the script that you can use to limit the priority 1 :
var person = g_user.userID;
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'sysIdOfYourGroup');
ir.addQuery('user', person);
ir.query();
if(ir.next()) {
g_form.removeOption(<fieldName>, <choiceValue>);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 07:00 AM
There are two ways you can do this:
1. You can leverage a custom system property that stores the sys_id of those groups in question. You then iterate through each of the sys_id values and check for membership on each.
2. You can create a custom role and add that role to those groups you want to have the options removed for. This will eliminate the need for the scratchpad variable since you can check for roles within a client script.
Please let me know which option you would like to pursue so I can formulate my solution accordingly.