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

Share your code.. and variable names (label name and database name)


I used this in a Catalog Client Script, applied to a Catalog Item, onLoad.


The variable name is "requested_for"   in the question table.   It is a reference to sys_user.



function onLoad() {


      //Change the requested for label


      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.


     


}



Thank you.


Mark,



I notice the code for modifying variables works only for variables that are NOT in containers. Or at least that is what my testing shows.



Are variables part of containers have different Element names or something? I'm not a DOM person so I am not sure how to determine what Element to find exactly.


neetusingh
Giga Guru

Thank you so much Mark!!!!!!! I hope it should not impact the other SRs.