How do I modify the Help Label of Form Fields With Client Scripts?

lesnettl
Tera Contributor

How do I modify the Help Label of Form Fields With Client Scripts? I have a requirement that I dynamically modify the label of a variable in the Service Catalog. I have found plenty of help to accomplish this:

https://community.servicenow.com/message/714821

http://www.servicenowguru.com/system-ui/ui-scripts-system-ui/modifying-label-form-fields-client-scri...

http://www.servicenowguru.com/system-ui/field-styles-service-catalog-variables/

With the suggestions in these resources, I am able to modify the label using Catalog Client Scripting. But I can't figure out how to dynamically modify the help label (normally shown as "More Information" adjacent to the label). Does anyone know how to do this?

Thank you!

1 ACCEPTED SOLUTION

Hi Larry,



Try this



var variableID = g_form.getControl('variableName').id;


var labelElement =   gel('help_'+variableID +'_wrapper');


labelElement.select('td').each(function(elmt) {


              if(elmt.className == '')


                elmt.innerHTML = "What text you want";


          });



Thanks and regards,


Pratik Limbore


View solution in original post

13 REPLIES 13

Anurag Tripathi
Mega Patron
Mega Patron

Hi Larry,



In Eureka mandatory marker comes as a part of Labels, so simply using inner HTML over rides the * too. So what I did was somehting like this


function onLoad() {


var x ;


var y;


var s='';


var lab1=g_form.getLabel("Field Name");


s ='New Label';     //This is the new label


lab1.innerHTML= fixLabel(lab1.innerHTML, s);


}



//This function extracts the mandatory control part, and just replaces the label


function fixLabel(x,y)


{


  var a = x.indexOf('span>');


  var b = x.substring(a+5);


  var t = x.replace(b, y);


  return t;


}



Hope this helps.


-Anurag

Thanks, but this seems to just change the label and not the text that appears when you click on the More Information link under the label. What my customer wanted was to dynamically change the helper text and not the label text.


ideamax
Mega Expert

Hi,



Inside an onload client script, create a function which modifies the label.



Eg


function changeFieldLabel(field, label, color, weight){


    try{


          var labelElement = $('label.' +   g_form.getControl(field).id);


          labelElement.select('label').each(function(elmt) {


                elmt.innerHTML = label + ':';


          });


          if(color)


                labelElement.style.color = color;


          if(weight)


          labelElement.style.fontWeight = weight;


    }catch(e){};


}








You can call this function from other clients scripts and the label will be changed, like onChange() of a field.


Hope this is what you meant by dynamically.




Thanks and regards,


Pratik Limbore


lesnettl
Tera Contributor

Thanks, but this seems to just change the label and not the text that appears when you click on the More Information link under the label. What my customer wanted was to dynamically change the helper text and not the label text.


Hi Larry,



Try this



var variableID = g_form.getControl('variableName').id;


var labelElement =   gel('help_'+variableID +'_wrapper');


labelElement.select('td').each(function(elmt) {


              if(elmt.className == '')


                elmt.innerHTML = "What text you want";


          });



Thanks and regards,


Pratik Limbore