Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Not able to add background colour for the field

Sanel
Tera Expert

Hi all,

I have a choice field which has four values 'Low,medium,high,critical', as per the value selected I have to display background colour in that field.I have Configured styles accordingly but still it doesnt show the background colour.

Can anyone just help me figure out what might be the issue?

find_real_file.png

find_real_file.png 

1 ACCEPTED SOLUTION

Hi @Sanel ,

I am back with some information for you.The problem you are facing in the client script is because you have marked the field read only via dictionary entry.

 

Am I right?

 I analysed it deeply & found

Other scenario where this approach fails when you have data policies defined for a field like in incident we have data policies on the priorty field.

I tried it.

If the field is custom field, you can proceed as:

Now what you can do:

  • First of all if you want to achieve it don't mark it readonly via sys_dictionary entry.It is not possible if it has been marked as readonly via dictionary entry.
  • Take this approach:

function onLoad() {
var rating=g_form.getValue("u_inherent_risk_score_rating");


if(rating == "1"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="green";
g_form.setReadOnly('impact',true);
}

 

if(rating == "2"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="light green";
g_form.setReadOnly('impact',true); 
}

 

if(rating == "3"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="yellow";
g_form.setReadOnly('impact',true); 
}

 

if(rating == "4"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="red";
g_form.setReadOnly('impact',true); 
}


}

But you have to create a list edit view to prevemt that field to be edited in the list view.

Mark it helpful/correct. 

 

Thanks

Sudhanshu

 

 

View solution in original post

25 REPLIES 25

Hi @Sanel ,

I am back with some information for you.The problem you are facing in the client script is because you have marked the field read only via dictionary entry.

 

Am I right?

 I analysed it deeply & found

Other scenario where this approach fails when you have data policies defined for a field like in incident we have data policies on the priorty field.

I tried it.

If the field is custom field, you can proceed as:

Now what you can do:

  • First of all if you want to achieve it don't mark it readonly via sys_dictionary entry.It is not possible if it has been marked as readonly via dictionary entry.
  • Take this approach:

function onLoad() {
var rating=g_form.getValue("u_inherent_risk_score_rating");


if(rating == "1"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="green";
g_form.setReadOnly('impact',true);
}

 

if(rating == "2"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="light green";
g_form.setReadOnly('impact',true); 
}

 

if(rating == "3"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="yellow";
g_form.setReadOnly('impact',true); 
}

 

if(rating == "4"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="red";
g_form.setReadOnly('impact',true); 
}


}

But you have to create a list edit view to prevemt that field to be edited in the list view.

Mark it helpful/correct. 

 

Thanks

Sudhanshu

 

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Something like below?

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue == "low") {
        control.style.backgroundColor = "green";
    } else if (newValue == "medium") {
        control.style.backgroundColor = "yellow";
    } else if (newValue == "high") {
        control.style.backgroundColor = "orange";
    } else if (newValue == "Critical") {
        control.style.backgroundColor = "red";
    }
}

Thanks @hozawa , your reply helped , just one problem is I have to keep my field as read only , and when I change it to read only through dictionary the Color is not applied.What can I do here?

Hitoshi Ozawa
Giga Sage
Giga Sage

I just did something like below to change color. Note that I made the selection values "low", "medium", "high", and "critical".

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue == 1) {
        control.style.backgroundColor = "green";
    } else if (newValue == 2) {
        control.style.backgroundColor = "yellow";
    } else if (newValue == 3) {
        control.style.backgroundColor = "orange";
    } else if (newValue == 4) {
        control.style.backgroundColor = "red";
    }
}

find_real_file.png

find_real_file.png

@hozawa Could you please try this by making your choice field as read only , and see if the colours are getting applied?Because in my place when I make the field read only the colours are not applied.