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

Maciej Kowalski
Kilo Expert

Hi, if you want to see what table name have this label then click on this with right mouse button, it open context menu in witch you should see table name for your label

No, Thats not what I am looking for

Harshad Wagh
Tera Guru

You have to write a display business rule on your table with following script.

    g_scratchpad.tableName = current.getClassDisplayValue();

 

And then in your on load client script use it like below.

alert(g_scratchpad.tableName);

i did the same , but i dont have to pop up an alert..I have to set the value which is coming with the scratchpad variable as the label(or u can say the form header). If the sracthpad variable returns Normal change  then my form header should show Normal Change Request. So therequirement is that i have to update my Form Header according  to the type of change record.

 

Ideally the Change Request form header has Change Request and the Request Number as below :


I want it a prefix as Normal/Emergency/Standard before Change Request depending upon the Change type.