How to hide the fields on form

Anil74
Tera Guru

Hi All,

Can anyone help me out how to hide fields on form using java script.

Hide.png

If the user selects None or In progress choices from the Internal Interview drop down, then hide Feedback and Interviewer fields which are highlighted in the red color.

i have tried with below code but its not working for me

g_form.setDisplay('Interviewer', false);

g_form.setDisplay('Feedback', false);

thanks

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hi Anil,



You need to write a UI policy on the Table with condition as Initial Interview is None OR Initial Interview is In Progress and Add 2 new UI policy actions for the fields Feedback and Interviewer. On the UI policy action for 2 fields, set Visible to false to accomplish your requirement.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

20 REPLIES 20

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Then calling g_form.setMandatory('Interviewer', false) before you call g_form.setDisplay should do the trick.


Actually, I just noticed that your field names are not likely right.   They are probably u_interviewer and u_feedback.


Hi Anil,



As Joe has mentioned you should make both the fields non-mandate as soon the user does not selects 'Completed' in the 'Internal Interview' field. For this you need to create/modify the onChange Client Script on the change of the 'Internal Interview' value. The script would be similar to below:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading) {


              return;


      }


     


      if (newValue != 'Completed'){   //Provide backend value of 'Completed'


              g_form.setMandatory('u_feedback', false);   //Provide field name of 'Feedback'


              g_form.setDisplay('u_feedback', false);   //Provide field name of 'Feedback'


              g_form.setMandatory('u_interviewer', false);   //Provide field name of 'Interviewer'


              g_form.setDisplay('u_interviewer', false);   //Provide field name of 'Interviewer'


      }


     


}



I hope this helps.Please mark correct/helpful based on impact


Venkateswarlu K
Mega Guru

Hi anil can u please try this or else u can also done this with ui policy am choosing with client script




function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }



  var a=g_form.getValue('internal interview');//give ur field value here


      if(a==none||inprogress){


              //Replace in above none with choice value and inprogress with value


              g_form.setVisible('feedback',false);


              g_form.setVisible('interviewer',false);


              alert('hiding this feedback,interviewer fields ');


      }


   


}


Venkateswarlu K
Mega Guru

Hi Anil


May i know the status of your   thread have u done this or else you need any more   help from us