Need to add multiple groups to a client script and business rule

michael_zeller
Kilo Explorer

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);

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

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;


}


View solution in original post

11 REPLIES 11

zica
Giga Guru

Zeller,



I advice you to do it in only one place, eitheir within a business rule (solution provided by Abhinay) or in a client script (Solution I provided above).


There is no much need to make a display business rule with scratchpad if the only one request is to hide one value depending on the user logged in.



That is my advice


michael_zeller
Kilo Explorer

Thank you everyone for your valuable input and taking time to respond. I am marking Abhinay's answer as correct because it was the quick fix I was looking for. However, I am still unsure why the consultant used this method--it seems like it will lead to issues later. I will continue to research and use everything you have provided. Thanks again to everyone!