How to get Element of label from form in Client script

indrasengupta
Tera Guru

Is there any way/method to get element of form label in Client script, i am trying to "setStyle" of label

indrasengupta_0-1714979636023.png

 

 

// Working for field
var requestorField = g_form.getElement('sys_display.' + g_form.getTableName() + '.u_authorized_requestor_s_full_name');

// Not working for form label
var requestorLabel = g_form.getElement('label.' + g_form.getTableName() + '.u_authorized_requestor_s_full_name');

 

 

  

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Basically it is absolutely not recommended to do this kind of DOM manipulation! 
Take the following example to see how to change the label color to red for the "Close code" field on a incident form:

function onLoad() {
    var objLabel = g_form.getLabel('incident.close_code'); 
    
    objLabel.style.color = 'red';
  }

 

View solution in original post

2 REPLIES 2

Maddysunil
Kilo Sage

@indrasengupta 

Please check below link should help you

https://www.servicenow.com/community/developer-forum/client-script-get-variable-label-and-values-on-... 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Maik Skoddow
Tera Patron
Tera Patron

Basically it is absolutely not recommended to do this kind of DOM manipulation! 
Take the following example to see how to change the label color to red for the "Close code" field on a incident form:

function onLoad() {
    var objLabel = g_form.getLabel('incident.close_code'); 
    
    objLabel.style.color = 'red';
  }