- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 10:07 PM
I have tried the following script with no success.
I want to hide the field in the attachment that is circled in red.
Is there something wrong in the way I'm writing it?
function onLoad() {
if (g_user.hasRoleExactly('x_540069_cmdb.test_roll1')) {
g_form.setVisible('kisyu_name', true);
g_form.setVisible('gyousya_name', true);
}
else {
g_form.setVisible('kisyu_name', false);
g_form.setVisible('gyousya_name', false);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 10:26 PM
I see you have added fields from one your reference field by dot walking.
To manage dot walked fields use below logic:
function onLoad() {
if (g_user.hasRoleExactly('x_540069_cmdb.test_roll1')) {
g_form.setVisible('kisyu_name', true);
g_form.setVisible('kisyu_name.maker_id.gyousya_name', true);
}
else {
g_form.setVisible('kisyu_name', false);
g_form.setVisible('kisyu_name.maker_id.gyousya_name', false);
}
always use field name in client script and if it is dot walked field then use highlighted part:
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 10:15 PM
Hi there,
What exactly is not working? What did you debug?
For example:
- Is the Client Script triggered at all?
- What is the outcome of g_user.hasRoleExactly, is it wat you expect?
-- Double check how you are testing, since it is g_user.hasRoleExactly!
- Is the IF or ELSE reached at all?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video 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
06-08-2021 10:26 PM
I see you have added fields from one your reference field by dot walking.
To manage dot walked fields use below logic:
function onLoad() {
if (g_user.hasRoleExactly('x_540069_cmdb.test_roll1')) {
g_form.setVisible('kisyu_name', true);
g_form.setVisible('kisyu_name.maker_id.gyousya_name', true);
}
else {
g_form.setVisible('kisyu_name', false);
g_form.setVisible('kisyu_name.maker_id.gyousya_name', false);
}
always use field name in client script and if it is dot walked field then use highlighted part:
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 11:42 PM
Thank you for the explanation.
I tried to do as you told me.
However, it did not succeed.
As a test, I did the following.
function onLoad() {
if (g_user.hasRoleExactly('x_540069_cmdb.test_roll1')) {
g_form.setVisible('kisyu_name.maker_id.gyousya_name', true);
g_form.setVisible('kisyu_name', true);
g_form.setVisible('install_date', true);
}
else {
g_form.setVisible('kisyu_name.maker_id.gyousya_name', false);
g_form.setVisible('kisyu_name', false);
g_form.setVisible('install_date', false);
}
}
Then, when the user does not have a role, the 'install_date' is indeed not displayed.
(Only 'install_date' was successful.)
It seems that only the other two fields, which are the most important ones, are not working correctly.
Is there still something wrong with the script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2021 12:02 AM
Okay, you can use debugger to see why these fields are still visible.
There is possibility that other UI Policies conflicting with this field.
Open record in your content window and watch field:
It will open field watcher at bottom, reload the form and check logs in field watcher to see whoch script making it visible.
Note: this field watcher will not work if you open record in new tab/window. Open it in ServiceNow content window only. As shown in first screenshot.
Thanks,
Anil Lande
Thanks
Anil Lande