Sections hide for specific group members

Sirri
Tera Guru

Hi All,

 

I have written below script. But still I'm not why another group members also getting same result.

Please check below script and let me know.

I have written onload client script.

 

var userID = g_user.userID;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group_name', 'RCO - Limited Contract Read');
gr.addQuery('user', userID);
gr.query();
if (gr.next()) {
alert(userID);
g_form.setSectionDisplay('notes', false);
g_form.setSectionDisplay('documents', false);
g_form.setSectionDisplay('terms_andconditions', false);
g_form.setSectionDisplay('renewalextension', false);
g_form.setSectionDisplay('financial', false);
g_form.setSectionDisplay('technical_information', false);
}

 

Please help me here If I have done anything wrong here.

 

Thank you

2 ACCEPTED SOLUTIONS

AshishKM
Kilo Patron
Kilo Patron

Hi @Sirri , 

 

Please refer this KB and match with sections.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0696583

and use the setDisplay() instead of setSectionDisplay();

 

g_form.setDisplay(<sectionName>, false);

 

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

It is not advisable to use GlideRecor din cluent script, so I would suggest use a combination of client script and Display BR

 

Step 1: Create a display Business rule with script as below

 

g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');  



Now update the client script as

 

function onLoad() {
  var usr = g_user.getUserID();
  var gate = g_form.getValue('u_field');
  if (gate == 'true' && !g_scratchpad.grp){
      g_form.setSectionDisplay('notes', false);
g_form.setSectionDisplay('documents', false);
g_form.setSectionDisplay('terms_andconditions', false);
g_form.setSectionDisplay('renewalextension', false);
g_form.setSectionDisplay('financial', false);
g_form.setSectionDisplay('technical_information', false);
    }
}
-Anurag

View solution in original post

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @Sirri , 

 

Please refer this KB and match with sections.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0696583

and use the setDisplay() instead of setSectionDisplay();

 

g_form.setDisplay(<sectionName>, false);

 

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

It is not advisable to use GlideRecor din cluent script, so I would suggest use a combination of client script and Display BR

 

Step 1: Create a display Business rule with script as below

 

g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');  



Now update the client script as

 

function onLoad() {
  var usr = g_user.getUserID();
  var gate = g_form.getValue('u_field');
  if (gate == 'true' && !g_scratchpad.grp){
      g_form.setSectionDisplay('notes', false);
g_form.setSectionDisplay('documents', false);
g_form.setSectionDisplay('terms_andconditions', false);
g_form.setSectionDisplay('renewalextension', false);
g_form.setSectionDisplay('financial', false);
g_form.setSectionDisplay('technical_information', false);
    }
}
-Anurag

Sandeep Rajput
Tera Patron
Tera Patron

@Sirri Do you have any mandatory field in any of these sections? If yes then the section would not be hidden.

 

Also make sure that The section name is lower case with an underscore replacing the first space in the name, and with the remaining spaces being removed, for example "Section Four is Here" becomes "section_fourishere". Other non-alphanumeric characters, such as ampersand (&), are removed. Section names can be found by using the getSectionNames() method.

 

Source: https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/client/c_GlideFormAPI#r_GF-SetS...