show/hide fields based on another fields vaule

tbofinger
Tera Contributor

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);

                               

                }

               

}

35 REPLIES 35

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

LinkedIn

I added this code, where will I be able to see the output?

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

LinkedIn

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

LinkedIn

pretty basic:

 

find_real_file.png