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
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

It also shows the Table Label i.e referring about the Text above the displayed value , like how to display the Text as Normal Change Request in header and Emergency Change Request?

Hi,

only way is to use DOM manipulation which is not good practice.

Regards
Ankur

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

Muhammad Khan
Mega Sage
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.

Will try to make the customer understand, otherwise will go by this.

Thanks for sharing , i tried and it worked !!!