Making the VIP name red in a task table Requested for field.

raj99918
Tera Contributor

Hi Team,

 

I want to make the Requested for field for VIP names in red on a task table , but reqested for is not the direct field on TASK table how can i achieve it by using the client scrip.

 

Note: Requested for on sc table field info: Dictionary Info: sc_task.request_item.requested_for

 

Thanks.

 

16 REPLIES 16

Tai Vu
Kilo Patron
Kilo Patron

Hi @raj99918 

Since you're working with OnLoad Client Script. The newValue from your script below is not defined.
You can try my adjustment below.

1. Remove the lines related to newValue 

2. Correct the variable name

3. Change the background attribute.

 

function onLoad() {
    var requestedForLabel = $('label.sc_task.request_item.requested_for');
    var requestedForField = $('sys_display.sc_task.request_item.requested_for');
    if (!requestedForLabel || !requestedForField)
        return;

    //The newValue below is undefined
    /*if (!newValue) {
        requestedForLabel.setStyle({
            backgroundImage: ""
        });
        requestedForField.setStyle({
            color: ""
        });
        return;
    }*/
    //Correct the field name below
    g_form.getReference('request_item.requested_for', viprequestedForCallback); 
}

function viprequestedForCallback(requestedFor) {
    var requestedForLabel = $('label.sc_task.request_item.requested_for').down('label');
    var requestedForField = $('sys_display.sc_task.request_item.requested_for');
    if (!requestedForLabel || !requestedForField)
        return;

    //check for VIP status
    if (requestedFor.vip.toString() == 'true') {
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        requestedForLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            paddingLeft: '30px'
        });
        requestedForField.setStyle({
            //color: "red" 
            background: "red" //change to background attribute
        });
    } else {
        requestedForLabel.setStyle({
            backgroundImage: ""
        });
        requestedForField.setStyle({
            //color: ""
            background: "" //change to background attribute
        });
    }
}

 

 

Cheers,

Tai Vu

raj99918
Tera Contributor

Hi @Timi,

Thanks for the reply. I have modified the onLoad script similar to what you have given so VIP icon is coming but VIP name in requested for is not showing in RED color. Below is my modified script:

 

function onLoad() {
    var callerLabel = $('label.sc_task.request_item.requested_for');
    var callerField = $('sys_display.sc_task.request_item.requested_for');
    if (!callerLabel || !callerField)
        return;

// if (!newValue) {
//      callerLabel.setStyle({backgroundImage: ""});
//      callerField.setStyle({color: ""});
//      return;


// }
    g_form.getReference('request_item.requested_for', vipCallerCallbackREQ);

}

function vipCallerCallbackREQ(caller) {

    var callerLabel = $('label.sc_task.request_item.requested_for').down('label');
    var callerField = $('sys_display.sc_task.request_item.requested_for');
    if (!callerLabel || !callerField)
        return;

   
    //check for VIP status
    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: ""});
    }
}

 

Thanks.

Hi @raj99918 

I copy exactly your script above, and it totally works fine for me.

Screenshot 2024-01-04 at 10.37.34.png

 

Make sure the Isolate script checkbox is unchecked. And also the field name "request_item.requested_for" is correct.

 

Cheers,

Tai Vu

raj99918
Tera Contributor

Hi @Tai Vu  I have unchecked the Isolate script checkbox and also the field name is  "request_item.requested_for" but still its not working for me

@raj99918 

are you sure the field is from RITM and not REQ?

request_item.request.requested_for

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader