show/hide fields based on another fields vaule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2019 01:25 PM
Hi everyone,
I’m new to Java scripting, so apologies in advance for the beginner question.
I am trying to build a user enablement form that will dynamically update the software list based on the department field.
I’ve created the UI policy script below, and while I’ve stopped getting script errors, the form doesn’t update as expected.
Any help would be appreciated.
function onCondition()
{
var dept = g_form.getValue('department');
if(dept == 'accounting'){
//show accounting apps
g_form.setDisplay('pep',Yes);
g_form.setDisplay('fas',Yes);
//hide non-accounting apps
g_form.setDisplay('salesforce',No);
g_form.setDisplay('factset',No);
g_form.setDisplay('dst',No);
}
}
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 07:00 AM
Still no changes to the form. Is there a way to turn on logging? I also tried to hide several fields at the beginning of the script, to indicate that the script is even running, no luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 12:30 PM
Could you please post a screenshot of your client script??
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2019 02:18 PM
Hi there,
Is the UI Policy triggered at all? For example putting an info message at the beginning of the UI Policy to check if it's triggered or that there is already something wrong with the UI Policy conditions.
Is the UI Policy intended for changing the fields onChange and onLoad or would onLoad already fulfill your requirement? If onLoad is what you are after, then UI Policy is not the best way to go.
If my answer helped you in any way, please then mark it as helpful.
Are you choosing on purpose for setDisplay? setVisible could also be an option.
Kind regards,
Mark
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-26-2019 05:57 AM
Hi Mark, Thanks for replying!
No, the policy doesn't seem to be triggered at all. The goal of the UI policy is to update the form based on the end user populating the Department field, so I don't think onLoad is what I am looking for.
I thought that I may need to change the function call from:
function onCondition()
To:
function onChange(control, oldValue, newValue, isLoading)
But when I make that change I receive a"missing function declaration for onCondition" error.
I also updated the script to use setVisible, from setDisplay, but that made no difference.
Any thoughts or advice is greatly appreciated.
thanks!
Troy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 05:56 AM
Hi there,
Just wondering:
if(dept == 'accounting'){
Is this an example or this the actual code? And if department a choice or string, or is it actually a reference field? If it's a reference field, then you should check the sys_id instead of the name of the department.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field