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:11 AM
Could you add for example the code below, somewhere before the IF. This to verify what is in the getValue.
g_form.addInfoMessage(g_form.getValue('department'));
This should be the same as what you have now in dept, though just to verify. If it differs, then this is a good lead.
If my answer helped you in any way, please then mark it as helpful.
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 07:23 AM
I added this code, where will I be able to see the output?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 07:25 AM
You should see this on top of your screen. If not... I guess the UI Policy is not triggered or stopping at some point (are there more typos?).
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 07:31 AM
How does the condition for the UI Policy looks like?
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 09:50 AM