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-27-2019 12:07 PM
Thanks Stephanie, can you provide an example of setting an alert statement?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2019 11:50 AM
Also, javascript can be very finicky embedded within ServiceNow. I have had issues with loops and counters consistently (e.g. if your for loop isn't working shift the ">" and or convert to a while loop). You'll get there:) Tricks of the trade.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2019 12:13 PM
function onCondition(){ alert('In the UI Policy!');
<the rest of your code.>
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2019 12:19 PM
yup, the alert triggers, the code is just finicky with the True/False field types.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2019 12:31 PM
Great! Those alert statements are going to become your best friends. So you are good to go now?