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

lesnettl
Tera Contributor

Thanks, Pratik. I used your code to create a UI Script that actually will change the help text that appears when the "More Information" link is clicked on a catalog variable. I can call this UI Script from a Catalog Client Script. (I combined your idea with the ideas from the others who helped me.)


Here is the UI   Script I created that works (I am using Eureka):


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


      try{


              var variableID = g_form.getControl(field).id;


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


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


                      if(elmt.className == ''){


                              elmt.innerHTML = label;


                      }


              });


              if(color)


                      labelElement.style.color = color;


              if(weight)


                      labelElement.style.fontWeight = weight;


      }catch(e){}


}


Hello,



I just wanted to run an 'update' to this answer. I got this to work but it seems that in Geneva and later (I have a Fuji instance) you need to get rid of "sys_original" that is a prefix to the ID.



var variableID = g_form.getControl(field).id;


var fixedID = variableID.replace("sys_original.", "");



Then you could go ahead and do:



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



and the code should work now. Thank you for the solution, this helped me out. You could also reference Show/Hide Service Catalog Variable Help Text - ServiceNow Guru   as that is where I got my answer. Thanks all!


Do you have a full script that will work in the Service Portal?



I am just trying to change a variable label in an OnChange script, but can't find anything that works in the Service Portal.



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Sorry I do not. I am just now starting to develop for the Service Portal. If I find a solution while I go along, I will make sure to follow up. My apologies and good luck!