Change the variable's label dynamically

neetusingh
Giga Guru

Hello Everyone!!!!

This is my project requirement that I am using the variable set - 'Requested For' in every SR. Exceptionally, in one SR, I have to change either its Label Name to "ID Name" or its Help Text that will lead to change in its behaviour in other SRs as well. But I dont want to affect the behaviour of "Requested For" in other SRs.

I want to change the Label of 'Requested For' on form loading without affecting the same in other SRs.

I tried the solution posted by Mark, http://www.servicenowguru.com/system-ui/ui-scripts-system-ui/modifying-label-form-fields-client-scri...
It works good for fields, not for variables.

Can anyone please help me in this or suggest something...

Regards/Neetu

1 ACCEPTED SOLUTION

Try this -



function onLoad() {


    var field = 'requested_for'; // requested_for is the database name for the variable


    var labelElement = $('label_' + g_form.getControl(field).id).select('label')[0];


    labelElement.innerHTML = 'Requested By'; // Requested By is the label name.


   


}



It should help..


View solution in original post

8 REPLIES 8

Mark Stanger
Giga Sage

Look in the comments on that article. There's a script supplied there that works for catalog variables.


Hi,


I applied the catalog variable version (in a Catalog client script) and it did not work:



function onLoad() {
//Change the "Requested For" label to "Requested By"
changeFieldLabel('Requested For', 'Requested By');
}


function changeFieldLabel(field, label){
try{
  var labelElement = $('label_' +   g_form.getControl(field).id);
  labelElement.select('label').each(function(elmt) {
    elmt.innerHTML = label;
  });
}catch(e){}
}




Any idea where I've gone wrong?


Try this -



function onLoad() {


    var field = 'requested_for'; // requested_for is the database name for the variable


    var labelElement = $('label_' + g_form.getControl(field).id).select('label')[0];


    labelElement.innerHTML = 'Requested By'; // Requested By is the label name.


   


}



It should help..


Hi,


It did not work, the original (Requested For) label remains intact.