How to change the "Incident" label on the incident form

Ivan Martez
ServiceNow Employee
ServiceNow Employee

I'm working with a customer who is requesting to have the header label on their incident form to read Parent Incident if the Parent field is not filled in. Seems like a simple request, but there was some DOM manipulation that had to be done. Here's what I did.

1. Used firebug to find the id, but guess what! The "Incident" label does not have an id but the element before it does.
2. Got that element (sysverb_view_change)
3. Here's the script. Place on the incident table as onLoad



function onLoad() {
//Script to change the header label on the incident form
var m = gel('sysverb_view_change').nextSibling; //getting the ID of the sibling that is before the incident label
var p = g_form.getValue('parent'); //getting the value of the parent field
var caller = g_form.getValue('caller_id'); //getting the value of the Caller field

if(p == '' && caller == ''){//If the parent and caller fields are empty
m.nodeValue = 'Parent Incident'; //Set the label to "Parent Incident"
}
if(p == '' && caller != ''){ //If the parent is blank and the caller is not blank
m.lastChild.nodeValue = 'Parent Incident'; //set the label to "Parent Incident"
}

}


NOTE: I have 2 different "if" statements here. On a new record the incident label is listed as a text node, easy to access. After a record has been submitted, the element changes from #text and is placed in a SPAN HTML element. After some research, I found that you can access and change that label using ("lastChild.nodeValue"). Text elements have read/write permissions which enable you to change them.

See the attached images for the before and after.

2 REPLIES 2

Mark Stanger
Giga Sage

I just found another use for this. You can eliminate the need to display the number field on a task form by using the same concept. Just put this in an 'onLoad' client script on the task table and make sure it inherits all the way down. Note that this requires that the number field be present on the form. Because we have to walk all over the DOM it's also got the risk of breaking during an upgrade.
I tried this in a global UI script so that it would work for numbers everywhere. That works as well, but there are places (such as the number maintenance table) that should keep their number field on the form. Probably better just to add this where you need it if you use it at all.



function onLoad(){
try{
//Check for a number field
if(g_form.getControl('number')){
//Hide the number field
g_form.setDisplay('number', false);
//Add the number to the form header
var formLabel = $('sysverb_view_change').nextSibling;
formLabel.nodeValue = formLabel.nodeValue + ' - ' + g_form.getValue('number');
formLabel.lastChild.nodeValue = formLabel.lastChild.nodeValue + ' - ' + g_form.getValue('number');
}
}catch(e){}
}


That's pretty neat actually. I set it up on the Task table and enabled the "Inherited" field so it would run on all the tables derived from task. The really great thing about it is the record number is in a consistent spot and you can regain the space from that field on the form.