Change background color of CHG assigned to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2015 10:04 AM
Hi again,
My script to change the color of the Change Request's assigned to based on the assigned to's score is always coloring the assigned to field the LightGreen color even when the assigned to's score is > 4. Do you have any ideas what I'm doing wrong? I really need this to run onLoad for the Change Request, but my coding didn't work for that either. Thank you so much for your continued help. I'm going to go through w3schools.com ASAP!
Client Script
Type: onChange
Table: Change Request
Field name: Assigned to
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading){
var callerField = $('sys_display.change_request.assigned_to');
if (!callerField)
return;
if (!newValue) {
callerField.setStyle({color: ""});
return;
}
g_form.getReference('assigned_to', assignedtoCallback);
}
function assignedtoCallback(assignee) {
var callerField = $('sys_display.change_request.assigned_to');
if (!callerField)
return;
//check for Assigned to CHG failure score.
if (assignee.u_failed_change_score <= '4') {
callerField.setStyle({background: "LightGreen"});
} else if (assignee.u_failed_change_score >= '5' && assignee.u_failed_change_score <= '15') {
callerField.setStyle({background: "LightBlue"});
} else if (assignee.u_failed_change_score >= '16' && assignee.u_failed_change_score <= '29') {
callerField.setStyle({background: "orange"});
} else if (assignee.u_failed_change_score >= '30') {
callerField.setStyle({background: "red"});
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2015 08:28 AM
I got it to work!! So it was easier than I was making it and I tried many ways that didn't work. Below is the code. Honestly, I don't understand how, but it is working onLoad and onChange....exactly how I need it to!
I appreciate your help, Kailey, very much as I could never have completed all of the scripting from this article and https://community.servicenow.com/thread/176785 without you.
Client Script
Type: onChange
Table: change_request
Field name: assigned to
function onChange(control, oldValue, newValue, isLoading) {
var callerField = $('sys_display.change_request.assigned_to');
if (!callerField)
return;
if (!newValue) {
callerField.setStyle({color: ""});
return;
}
g_form.getReference('assigned_to', scoreCallerCallback);
}
function scoreCallerCallback(assgnd) {
var callerField = $('sys_display.change_request.assigned_to');
if (!callerField)
return;
//check for VIP status
if (assgnd.u_failed_change_score <= 4) {
callerField.setStyle({background: "LightGreen"});
} else if (assgnd.u_failed_change_score >= 5 && assgnd.u_failed_change_score <= 15){
callerField.setStyle({background: "LightBlue"});
} else if (assgnd.u_failed_change_score >= 16 && assgnd.u_failed_change_score <= 29){
callerField.setStyle({background: "orange"});
} else if (assgnd.u_failed_change_score >= 30){
callerField.setStyle({background: "red"});
}
}