How to get the value of Label of a Table at client side ?

Servicenow12
Tera Contributor

How to get the value of Label of a Table at client side ?

The backend name of Label Field is 'label' only. To get table name we have g_form.getTableName(). How to get the table label name as shown in below scrrenshot. Please suggest

 

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage

Well, if you want to change the header title then you might have to use DOM which is not recommended.

For this purpose, we have type field on the form, right?

If you still want to go with DOM, then try utilizing the below scripts on change_request table.

Display Business Rule.

(function executeRule(current, previous /*null when async*/ ) {

    var chgType = current.type.getDisplayValue();
    var tblName = current.getClassDisplayValue();

    g_scratchpad.title = chgType + ' ' + tblName;

})(current, previous);

onLoad() Client Script 

function onLoad() {

    var arr = top.document.getElementsByClassName('navbar-title-caption');
    arr[0].innerHTML = g_scratchpad.title;

}

 

Output:

 

In case, if it does not work then you can uncheck Isolate script check box in the client script and try again. See the below image for reference.

View solution in original post

18 REPLIES 18

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I haven't come across any use-case from customer to get table label in client side.

regards
Ankur

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

Yes, but can you help me with the approach to achieve this ..is it feasible ?

Hi,

you can use display business rule on your table + onLoad client script

Display BR:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
		g_scratchpad.tableLabel = current.getClassDisplayValue();

})(current, previous);

onLoad client script:

function onLoad(){
	alert(g_scratchpad.tableLabel);
}

regards
Ankur

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

This i have already tried but how to set the value of Form Header using client script ? 

Hi,

the form header always shows the field which is Display=true on that table

Regards
Ankur

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