Change background color of read only field

Marcel H_
Tera Guru

I know that this is one of those types of things that aren't a big deal, and honestly I can deal without it, but it's driving me crazy not to be able to do this the way that I expect. I've read a lot of posts here in the community, and on the internet in general, but none of the solutions really seem to work for me for what I'm trying to do. It seems like it should be an easy thing to do, and something that should be easier to configure in the base system, since visual queues draw someone's eye to something that might need attention.

Of course the thing that I'm trying to do is change the background color of a field on a form, which seems to be difficult at best. Setting the style so it displays in the list is simple and straight forward, but forms are apparently much different. I've used a ton of examples from the posts here, and I think the closest that I got was Change form color on state change

function onChange(control, oldValue, newValue, isLoading) {

var elementID = gel("incident.priority");

switch(newValue) {

case "1": elementID.style.backgroundColor = "red"; break;

case "2": elementID.style.backgroundColor = "tomato"; break;

case "3": elementID.style.backgroundColor = "orange"; break;

case "4": elementID.style.backgroundColor = "yellow"; break;

case "5": elementID.style.backgroundColor = "green"; break;

default: elementID.style.backgroundColor = "white"; break; } }

The above script from that article works just fine on the Incident table, but modifying the script for my custom table, I'm getting nowhere. I've tried a ton of different scripts, in various configurations/modifications and used Client Scripts (onChange, onLoad), UI Policy scripts, and scripts in the variable field of a field style record. My custom table is extended from ast_leases (which itself is extended from the ast_contracts table) and I'm trying to change the background color of the Expiration Level field (expiration) on the form.

Part of the reason that I would like the background color changed, is that the field is also being pulled into another table's form as part of a reference, and the users are more likely to see if there than in the list of records for the originating table.

Part of what is really driving me crazy though is that I can see other places in the system where fields on forms are colored, so it seems like it should be able to be done without all of the trouble that I've been having:

find_real_file.png

5 REPLIES 5

Kunal Jha
Giga Expert

Marcel ,



Use below code and you will get the result:



I have custom table with one field as "User" and its a drop down field with 3 options as {both, engineer,end_user}



client script on change of User:


function onChange(control, oldValue, newValue, isLoading) {


var elemet = g_form.getElement('u_user');


var eleform = g_form.getFormElement();


alert(newValue);


switch(newValue) {


  case "both": elemet.style.backgroundColor = "red"; break;


  case "engineer": elemet.style.backgroundColor = "tomato"; break;


  case "end_user": elemet.style.backgroundColor = "orange"; break;


  default: elemet.style.backgroundColor = "white"; break; } }



result:


find_real_file.png


find_real_file.png


find_real_file.png


Thanks Kunal, looks like the script should work without any issues normally



I think the complication that I'm having is probably because the Expiration Level is also a reference field. I seem to recall reading that reference fields hide a specific property (read so much I don't recall exactly now) that makes it more difficult to color them. That being said, the alert in the script you provided does bring back a value, which looks like a sys_id. I put those values into the case argument, but still no change in color (again, probably due to the reference field issue).



function onChange(control, oldValue, newValue, isLoading) {


var elemet = g_form.getElement('expiration');


var eleform = g_form.getFormElement();


alert(newValue);


switch(newValue) {


  case "c752e78ec3103000c111113e5bba8f3a": elemet.style.backgroundColor = "darkgray"; break;


  case "0f72e78ec3103000c111113e5bba8fb2": elemet.style.backgroundColor = "coral"; break;


  case "dda2e38ec3103000c111113e5bba8fab": elemet.style.backgroundColor = "orange"; break;


  case "a6c2e38ec3103000c111113e5bba8f84": elemet.style.backgroundColor = "yellow"; break;


  default: elemet.style.backgroundColor = "white"; break; } }


Marcel - if that is the case then keep a button beside reference field and if the value change the change the color of that macro button.


I didn't saw you mentioned about reference field so my mistake.