How to highlight vip user in catalog task

rahul16
Giga Guru

find_real_file.png

how to make Requested for to red text and VIP badge if a user is VIP in sc_task table

The label of requested for is below 

find_real_file.png

 

find_real_file.png

I take the reference of OOTB script of incident but that not worked for me

function onChange(control, oldValue, newValue, isLoading) {    
    var callerLabel = $('label.sc_task.requested_for');
    var callerField = $('sys_display.sc_task.requested_for');
    if (!callerLabel || !callerField)
        return;
    if (!newValue) {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
        return;
    }
    g_form.getReference('request_item.request.requested_for', vipCallerCallback);
    
}

function vipCallerCallback(caller) {
    var callerLabel = $('label.sc_task.requested_for').down('label');
    var callerField = $('sys_display.sc_task.requested_for');
    if (!callerLabel || !callerField)
        return;
    if (caller.vip == '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({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}
1 ACCEPTED SOLUTION

rahul16
Giga Guru

function onLoad() {
    var reqfor = g_form.getReference('request_item.requested_for');
    var reqforLabel = document.getElementsByClassName('col-xs-12 col-md-3 col-lg-4 control-label')[1];
    var reqforField = document.getElementById('sys_display.sc_task.request_item.requested_for');
    if (reqfor.vip == 'true') {
        reqforLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: "5% 45%"
        });
        reqforField.style.color = 'red';
    } else {
        reqforLabel.style.backgroundImage = '';
        reqforField.style.color = '';
    }
}

 

This work for me finally

View solution in original post

4 REPLIES 4

Kartik Sethi
Tera Guru
Tera Guru

Hi @rahul 

 

You can follow the Client Script example which is present OOTB.

Link: https://<instance_name>.service-now.com/sys_script_client.do?sys_id=8f0b3ee00a0a0b5700e75f4aaabe4953

You can add the code to modify the text color of the field.

 

Remark: Make sure the field Isolate Script is set to false


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

find_real_file.png

i already did that but non worked

 

function onChange(control, oldValue, newValue, isLoading) {    
    var callerLabel = $('label.sc_task.requested_for');
    var callerField = $('sys_display.sc_task.requested_for');
    if (!callerLabel || !callerField)
        return;
    if (!newValue) {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
        return;
    }
    g_form.getReference('request_item.request.requested_for', vipCallerCallback);
    
}

function vipCallerCallback(caller) {
    var callerLabel = $('label.sc_task.requested_for').down('label');
    var callerField = $('sys_display.sc_task.requested_for');
    if (!callerLabel || !callerField)
        return;
    if (caller.vip == '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({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}

OlaN
Giga Sage
Giga Sage

Hi,

If you don't need the highlighting of the text, you could easily create a onDisplay Business rule that adds an info message when the user is marked as VIP.

No coding required, just dotwalk on the related field in the condition builder of the Business rule.

find_real_file.png

rahul16
Giga Guru

function onLoad() {
    var reqfor = g_form.getReference('request_item.requested_for');
    var reqforLabel = document.getElementsByClassName('col-xs-12 col-md-3 col-lg-4 control-label')[1];
    var reqforField = document.getElementById('sys_display.sc_task.request_item.requested_for');
    if (reqfor.vip == 'true') {
        reqforLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: "5% 45%"
        });
        reqforField.style.color = 'red';
    } else {
        reqforLabel.style.backgroundImage = '';
        reqforField.style.color = '';
    }
}

 

This work for me finally