How can i hide fields based on user and role?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 02:52 AM
In my custom table have two fields
1.Manager Name
2.Mobile phone
When ever i am Impersonate to User Kasi Rao with Admin role on custom table above two fields will be displayed.
My requirement is like this
When ever i am Impersonate to User Karthik Reddy with Custom role .I want hide two field.
Is it possible to hide fields based on Impersonate User?
If possible please help me.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 03:01 AM
Hi,
Give your Custom Role to the users you want and then Based on role you can show or hide the fields as mentioned below:
Write an On Load Client script:
function onLoad()
{
var role_check = g_user.hasRole('Mention the Role Name');
if(role_check == 'admin')
{
g_form.setDisplay('Field Name', false);
}
else if(role_check == 'Mention your Custom Role')
{
g_form.setDisplay('Field Name', true);
}
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 04:18 AM
Hello Srivastava
I have tried your code but still not working.
I have write client script like this
This is my custom table by default User Kasi Rao have "admin" role only
Up to here everything work's fine
When i am impersonate to User Karthik Reddy have x_163353_campus_pr.manager(custom role)
Here i want manager field will hide but not working it's still showing manager field.
Please help me in this requirement i am new to ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 07:52 AM
the role_check variable will return true or false depending on whether the user has that role eg:
function onLoad()
{
var role_check = g_user.hasRole('Mention the Role Name');
if(role_check == true){
g_form.setDisplay('Field Name', true);
}
else if(role_check == false){
g_form.setDisplay('Field Name', false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 08:00 AM
Hello David
same script is not working for Reference field
here
Field Name = Manager Name (Reference field)