Hi,How do I make one of the section views read only for some people and give write access to the others?

Jasmine Rego
Kilo Explorer

Hi,How do I make one of the section views read only for some people and give write access to the others?

6 REPLIES 6

snehabinani26
Tera Guru

Hi Jasmine,



Do you want to hide section based on role.



g_form.setSectionDisplay('schedule', false);




Thanks for the answer Sneha. But no i am not looking for hiding the section.


My requirement is


1)Section X is visible on certain condition(done that)


2)All fileds under X, say 20 fields are read only(done that)


3)These fields should be editable only by certain people.(Need help)


    The problem here is ACL is applied on one field at a time.But i need ACL to be applied for multiple fields at a time and make people with certain role have                   access to edit all these fields in this particular section.The rest of the people will just have it in read only status.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Jasmine,



To add, Please refer the below link for more info on how to validate roles at client side i.e g_user.hasRole('PASSROLE NAME');


http://wiki.servicenow.com/index.php?title=GlideUser_(g_user)#hasRole


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setSectionDisplay


shloke04
Kilo Patron

Hi,



Can you elaborate your requirement? As per my assumption, If you want to Restrict users from Writing to the fields present in a particular section then you can either write a UI Policy or a client script to make it a Read Only field by checking for the User Roles for the logged in User. Please refer the script below for reference:



Script:



On Load Client Script on the Desired Table say for Example on Incident Table:



function onLoad() {


    //Type appropriate comment here, and begin script below


    var logged_user = g_user.hasRole('itil');                     //Replace your Role for which you want to check here


  if(logged_user)


  {


  g_form.setReadOnly('field_name',false);             //Replace your Field name here


  }


  else


  {


  g_form.setReadOnly('field_name',true);       //Replace your Field name here


  }


}




In case if you want to hide Section for uses with particular Role then you can use   the Code snippet provided by Sneha above in an On Load Client Script as below:



function onLoad() {


    //Type appropriate comment here, and begin script below


    var logged_user = g_user.hasRole('itil');


  if(logged_user)


  {


  g_form.setSectionDisplay('section_name',true);


  }


  else


  {


  g_form.setSectionDisplay('section_name',false);           //Make Sure the Section Name is in Small Case letters


  }


}



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke