- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:39 AM
Hi,
I want to make my fields visible on form depending a variable "Disponent" whose type is "list".
Reference to this fields are three fields PM, MM, PP. Depending on them I have three fields on form PM users, MM users, PP users which should be displayed when PM, MM, PP respectively are selected into Disponent.
And here is my client script (on change of field Disponent)-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var x=g_form.getValue('u_disponent');
if(x=='')
{
g_form.setVisible('u_pm_user',false);
g_form.setVisible('u_mm_user',false);
g_form.setVisible('u_pp_user',false);
}
if(x=="296388e1db7332002667d001cf961996")
{
alert("PM user")
g_form.setVisible('u_pm_user',true);
g_form.setVisible('u_mm_user',false);
g_form.setVisible('u_pp_user',false);
}
if(x=='31334ce5db3332002667d001cf961926') // MM
{
alert("MM true")
g_form.setVisible('u_pm_user',false);
g_form.setVisible('u_mm_user',true);
g_form.setVisible('u_pp_user',false);
}
if(x=='8f63c42ddb3332002667d001cf961948') //PP
{
alert("PP true")
g_form.setVisible('u_pp_user',true);
g_form.setVisible('u_mm_user',false);
g_form.setVisible('u_pm_user',false);
}}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:50 AM
In the UI policy, your condition would be:
Disponent | contains | (user)
Here's an example on the incident watch list field I just built.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:42 AM
Hi Ketki,
Since a list field is a comma separated list of sys_ids, your "==" is only looking for exact matches. You'll need to do more of a 'contains' operation like this:
if (x.indexOf('SYS_ID_HERE') >= 0) {
// sys_id was found in the list
}
Any thoughts of doing this with a UI policy (or a few) to make it codeless and easier to read/maintain?
http://wiki.servicenow.com/index.php?title=Creating_a_UI_Policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:48 AM
Hi Chuck,
Thanks for your reply.
Using indexOf didnot help, same issue.
But, how will this be done via UI policy as there can be multiple values in the List variable type.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 06:01 AM
Thanks Chuck,
It helped me