How to change the background color(blue) of caller Id on incident form if user is terminated (terminate is a field on sys_user table). Configure style is not working on it as caller id is a reference field.

Manju Rani
Kilo Explorer

How to change the background color(blue) of caller Id on incident form if user is terminated (terminate is a field on sys_user table). Configure style is not working on it as caller id is a reference field.

So the question is how to change a reference field background color on incident form based on the condition from sys_user table. 

1 REPLY 1

chrisperry
Giga Sage

Hi there,

You can achieve this requirement by inserting new from the existing OOTB onChange Client script running on incident table 'Highlight VIP Caller' -- replace xyz in this link with your instance name to view: https://xyz.service-now.com/sys_script_client.do?sys_id=8f0b3ee00a0a0b5700e75f4aaabe4953&sysparm_record_target=sys_script_client&sysparm_record_row=1&sysparm_record_rows=4&sysparm_record_list=sys_class_name%3Dsys_script_client%5EnameCONTAINSvip%5EORDERBYorder

Then all you would need to do is update line 22 with your Terminate sys_user condition, remove line 27 for adding the VIP icon, and update line 28 to set background color to blue: 

function onChange(control, oldValue, newValue, isLoading) {
    var callerLabel = $('label.incident.caller_id');
    var callerField = $('sys_display.incident.caller_id');
    if (!callerLabel || !callerField)
        return;

    if (!newValue) {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
        return;
    }
    g_form.getReference('caller_id', vipCallerCallback);
}

function vipCallerCallback(caller) {
    var callerLabel = $('label.incident.caller_id').down('label');
    var callerField = $('sys_display.incident.caller_id');
    if (!callerLabel || !callerField)
        return;

    //check for Terminate
    if (caller.terminate == true) {
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        //callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
        callerField.setStyle({
            backgroundColor: "blue"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            backgroundColor: ""
        });
    }
}

Lastly, be sure to set Isolate script = false for your new client script:

find_real_file.png

Result:

find_real_file.png

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry