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

can you share the screenshot of your BR and Client script?

Thanks

Harshad

On Display BR :

    
var ticktype = current.ticket_type.getDisplayValue();
var tb_name = current.getClassDisplayValue();
    
var tab_label = ticktype + " " + tb_name;

g_scratchpad.test = tab_label;

 

On Load CS :

alert(g_scratchpad.test);

g_form.setLabelOf('label', g_scratchpad.test);

Muhammad Khan
Mega Sage
Mega Sage

Can you explain your business requirement like why there is need of table label ?

So that by opening the record one can easily identify the type of Change Request by reading out at Form Header

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