- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 01:08 PM
Hey Guys I am attempting to rewrite the label if a user has itil role..
however I believe the syntax maybe off.. can you help?
the field name is called u_comments
function onLoad() {
if (!g_user.hasRole("itil"))
return;
var field = 'u_comments';
var fieldFormName = g_form.getTableName() + "." + field;
var fieldLabelName = "label." + fieldFormName;
var ctrl = $(fieldLabelName);
if (!ctrl)
return;
var label = ctrl.select('label')[0];
if (!label)
return;
var s = label.innerHTML;
label.innerHTML = s.substring(0, s.length — 1) + ' (' + getMessage('Customer visible') + '):';
//label.setStyle({fontWeight:"bold"});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 02:27 PM
Mark Stanger (Crossfuze) Resolved this for me
function onLoad() {
if(!g_user.hasRole('itil'))
return;
//Change the description label to 'My New Label' with bold red text
changeFieldLabel('u_comments', 'My New Label', 'red', 'bold');
}
function changeFieldLabel(field, label, color, weight){
try{
var labelElement = $('label.' + g_form.getControl(field).id);
labelElement.select('label').each(function(elmt) {
elmt.innerHTML = label + ':';
});
if(color)
labelElement.style.color = color;
if(weight)
labelElement.style.fontWeight = weight;
}catch(e){};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 01:21 PM
Here is a wonderful post on ServiceNow Guru that helps with this very question. » Modifying the Label of Form Fields With Client Scripts
Does that point you in the right direction?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 01:36 PM
Yeah that's how I reached this point, im not sure why its not populating ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 02:27 PM
Mark Stanger (Crossfuze) Resolved this for me
function onLoad() {
if(!g_user.hasRole('itil'))
return;
//Change the description label to 'My New Label' with bold red text
changeFieldLabel('u_comments', 'My New Label', 'red', 'bold');
}
function changeFieldLabel(field, label, color, weight){
try{
var labelElement = $('label.' + g_form.getControl(field).id);
labelElement.select('label').each(function(elmt) {
elmt.innerHTML = label + ':';
});
if(color)
labelElement.style.color = color;
if(weight)
labelElement.style.fontWeight = weight;
}catch(e){};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2017 01:40 AM
Hi nysbigdave/ mark.stanger
I am trying to change field label color to red in incident form by onload client script .
But as soon as I change the choice option of that field tha field label color changes red to black .
Can you guide me why this is happening and what to do solve this.
Please refer below screenshots.
Before changing choice value of any field .
After changing choice value of system field , severity . Field labels are turning to black color.
Please help me out .ctomasi
Thanks
Aastha