Get field/column label on client side

SNDEV27
Tera Contributor

Hi, 
Is there any way to get field/column label on client side script ?
I tried following 2 ways but no luck.

1. var a = g_form.getLabel('business_group'); 
2. var a = g_form.getLabel('cmdb_ci_business_app.business_group'); //table.backend_name


Can we achieve this ?

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@SNDEV27 The correct method to extract the label is getLabelOf. Here is an example.

 

if (g_user.hasRole('itil')) {
    var oldLabel = g_form.getLabelOf('comments');
    g_form.setLabelOf('comments', oldLabel + ' (Customer visible)');
}

 

Please refer to this URL https://developer.servicenow.com/dev.do#!/reference/api/xanadu/client/c_GlideFormAPI#r_GlideFormGetL... for more information

View solution in original post

4 REPLIES 4

SAI VENKATESH
Tera Sage
Tera Sage

Hi @SNDEV27 

 

Can you try in this: 

g_form.getLabelOf('field_name');

 

Thanks and Regards

Sai Venkatesh

 

Sandeep Rajput
Tera Patron
Tera Patron

@SNDEV27 The correct method to extract the label is getLabelOf. Here is an example.

 

if (g_user.hasRole('itil')) {
    var oldLabel = g_form.getLabelOf('comments');
    g_form.setLabelOf('comments', oldLabel + ' (Customer visible)');
}

 

Please refer to this URL https://developer.servicenow.com/dev.do#!/reference/api/xanadu/client/c_GlideFormAPI#r_GlideFormGetL... for more information

Juhi Poddar
Kilo Patron

Hello @SNDEV27 

For field label in client script you can refer this thread get Element of label from form in Client script

For column label in script include you can refer this get column labels of fields in a table

 

If this helped please hit like and mark it as an accepted solution.

 

Thank You 

Juhi Poddar 

Ankur Bawiskar
Tera Patron
Tera Patron

@SNDEV27 

the correct method is below, what's your business requirement

g_form.getLabelOf('fieldName')

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader