ServiceNow :
note: unlike the number field for example, styles didn't appear to have any effect on the reference field on the form (though list view seemed fine)
in below example an AJAX call is made from the client script -on task but inherited- to dotWalk to a CMDB ref value (service_offering.DSSO)
(note below example is reference field using g_form.getDisplayBox, for dropdown use g_form.getControl instead )
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if (g_form.isNewRecord()){ return};
}
var sTN = g_form.getTableName();
if (sTN=='incident'||sTN=='sc_req_item'||sTN=='change_request'||sTN=='problem') {
//--get the service_offering.u_dts_standardised_support_offering
//--(Bronze, Silver, Gold)
var ga = new GlideAjax('task_fieldstyles');
ga.addParam('sysparm_name', 'getServiceOffering_DTS_SOG');
ga.addParam('sysparm_serviceoffering', g_form.getValue('service_offering'));
ga.getXMLAnswer(function(answer) {
var sVal = answer;
var sLbl = g_form.getLabel('service_offering');
var sFld= g_form.getDisplayBox('service_offering');
sFld.style.backgroundColor = 'blue';
if (sVal == 'gold') {
sLbl.style.backgroundColor = '#BFA000';
sLbl.style.color = 'white';
sFld.style.backgroundColor = '#BFA000';
sFld.style.color = 'white';
}
if (sVal == 'silver') {
sLbl.style.backgroundColor = '#C0C0C0';
sLbl.style.color = 'white';
sFld.style.backgroundColor = '#C0C0C0';
sFld.style.color = 'white';
}
if (sVal == 'bronze') {
sLbl.style.backgroundColor = '#CD7F32';
sLbl.style.color = 'white';
sFld.style.backgroundColor = '#CD7F32';
sFld.style.color = 'white';
}
});
}
}
Comments
Post a Comment