Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Tried this code, and now the text does not display at all:





function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
          return;
    }


    //Type appropriate comment here, and begin script below
var val =g_form.getvalue('designate_proxy');
if(val == 'Yes'){

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';
  }


}
  }
if(val == 'No'){

var elem = document.getElementsByClassName('sc-help-text annotation-wrapper');
  for (var i=0;i<elem .length;i+=1){

  if (elem [i].style.display === 'none') {
  elem[i].style.display = 'none';
  }


}
}
}