How to change the text color of a field

Matheus Rissi2
Tera Expert

Hello everyone,

I'm having the following problem:
I have to change the field color to red when the user is VIP.
But I'm not getting it, I've already created the style and the client script, but I can't change it, neither in the form nor in the table.

If you can help, thank you very much


Style:
javascript:current.opened_by.vip==true

background-image: url('images/icons/vip.gif');
background-repeat: no-repeat;
color:red;

 

I've tried by client script but I can't change

function onLoad() {
    //Type appropriate comment here, and begin script below
    var element = g_form.getElement('current.opened_by.vip');
    if (element == True) {
        element.style.color = "red";
    }
}


Note: I don't know if that could be the reason, but this field is for the global application, I'm having to create this change in the human resources application

2 REPLIES 2

Snehangshu Sark
Giga Guru

try this:

 

function onLoad() {

    var element = g_form.getControl('<field_name>');
    element.style.backgroundColor = "rgb(255,0,0)";

}

 

note: you can't set field colour to a different table. So, dot-walking would not work in the '<field_name>'.

 

In addition, if condition logic should be in the below format - 

if(element == 'true')

 

Regards,

Snehangshu Sarkar

Anil Lande
Kilo Patron

Hi,

Please check below link:

https://community.servicenow.com/community?id=community_question&sys_id=0b02ac07dbdac010feb1a851ca96...

you can use something like this:

var caller = g_form.getReference('caller_id',callback);
function callback(caller){
if(caller.vip == 'true'){
var labelcolor = document.getElementById('label.incident.caller_id');
labelcolor.style.color = 'red';
}
}

 

Thanks,
Anil Lande