The CreatorCon Call for Content is officially open! Get started here.

Make fields visible on form Based on another field

ketki_j
Tera Contributor

Hi,

I want to make my fields visible on form depending a variable "Disponent" whose type is "list".

find_real_file.png

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.

find_real_file.png

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

}}

1 ACCEPTED SOLUTION

In the UI policy, your condition would be:



Disponent | contains | (user)



Here's an example on the incident watch list field I just built.


find_real_file.png


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

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


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.


In the UI policy, your condition would be:



Disponent | contains | (user)



Here's an example on the incident watch list field I just built.


find_real_file.png


Thanks Chuck,



It helped me