- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 05:54 AM
Hello,
I have an on display business rule that checks if a user is an admin. I would like to hide a form section with the name of 'TEST' if the user does not have the admin role. What is the code to hide the section?
Heres what I have so far:
(function executeRule(current, previous /*null when async*/ ) {
var usr = gs.getUser();
if (!usr.hasRole('admin')) {
} else if (usr.hasRole('admin')) {
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 05:58 AM
Hi JJG,
I don't know if this can be done with Business Rule actually. Though a example onLoad Client Script:
function onLoad() {
if(!g_user.hasRole('admin')) {
g_form.setSectionDisplay('your_section_name', false);
}
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 05:58 AM
Hi JJG,
I don't know if this can be done with Business Rule actually. Though a example onLoad Client Script:
function onLoad() {
if(!g_user.hasRole('admin')) {
g_form.setSectionDisplay('your_section_name', false);
}
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 06:17 AM
Its not possible server-side?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 06:20 AM
Don't know for sure. Though never found anything server side on this before.
Don't really like this myself, because it is client side, and client side can sometimes be slow/corrupt/able to influence.
If these for example are important fields, you might want to consider restricting with ACL's. That way you could hide (read acl) the fields server side, only thing would be that the section would be empty (for non-admin), section which you only need to hide with client script which feels more acceptable.
Obviously, this is far more work 😞
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2020 06:04 AM
Hi,
Try below code to achieve above functionality using client script.
function onLoad() {
if(g_user.hasRoles('admin') == true) {
g_form.setSectionDisplay('TEST', true);
}
else{
g_form.setSectionDisplay('TEST', false);
}
}
Thanks,
karthik