How to make help text display conditionally

nicolemccray
Tera Expert

I have an 'onLoad' script that will make the help text always visible.   But instead, I need an onChange script that will display it conditionally.   If 'designate_proxy' field = yes, the help text should expand:

How can I modify the script for this to work?:

    var myVar = g_form.getControl('designate_proxy');

    toggleHelp(myVar.id);

1 ACCEPTED SOLUTION

Nana5
Mega Guru

Hi Nicole,


  Please try somthin like below:



function onChange(){



var val =g_form.getvalue('designate_proxy');


if(val == 'true'){



var elems = document.getElementsByClassName('sc-help-text annotation-wrapper');


  for (var i=0;i<elems.length;i+=1){



  if (elems[i].style.display === 'none') {


  elems[i].style.display = 'block';


  }



}


  }



let me know if you not able to get becuase here sode i didn't tested but logic should be


first get the checkbox value and based on true false you have to display the helptext.



if its not works please let me know .




thanks


View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nicole,



There is nothing in ServiceNow which allows dynamic help text to be shown/hide. Something you can do is with HTML DOM manipulation.


If I find anything then I will put it here.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nicole,



Have following jquery logic in your onChange client script.


the highlighted part you can find by finding the html element.


The html id for my example is : question_help_IO_809e9d3c4f813200fc11fa218110c78b_toggle_value


It would be different in your case.



function onChange(){



if(newValue == 'yes'){


$j('#question_help_IO_809e9d3c4f813200fc11fa218110c78b_toggle_value').show(); // show the help text div


}


else if(newValue == 'no'){


$j('#question_help_IO_809e9d3c4f813200fc11fa218110c78b_toggle_value').hide(); // hide the help text div


}



}



Screenshot for DOM:



help-text-dom.jpg



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

I tried why you proposed and in my case it is not working.

 

Please see below screenshot.

 

find_real_file.png

 3D85f46a5387830110714dfcc5dabb35ce = This is sys_id of help_text field.

I am trying to display the help text when age is twelve.

 

Could you please suggest!

Hello Vishal

Go to List View of Client script add isolate script checkbox

If it true make false or Vice Versa

Please mark as Helpful if it helped to resolve your query

Thanks

Hemant Kumar Ch