On Load highlight Client Script for SC_TASK not highlighting

lindac
Kilo Explorer

Hi,

I have created the following On Load client script. The table is sc_task and the field I want to highlight is Request For. The Request For is actually on the Request table and we just reference it on the sc_task table. I am trying to have the Label and Field highlight to Red if the name in the Request for field is a VIP. I am not getting anything highlighted.

I have tried dot walking as shown below and I have tried just using sc_task.requested_for and nothing seems to work.

I have also tried this on the sc_request as a test to see if I could get it to work since on the Request table the Requested For field is not referenced but it still does not work.

The bulk of this client script was taken from an OOB On Change rule for incident called Highlight VIP Caller which is working. I don't need an On Change client script for the sc_task because the Request For field will not change once the request has been created.

Thank you for any assistance that is provided.


function onLoad() {
//get the requested for object so we can access fields
var reqfor = g_form.getReference('request_item.request.requested_for');
var reqforLabel = document.getElementById('label.request_item.request.requested_for');
var reqforField = document.getElementById('sys_display.request_item.request.requested_for');
//check for VIP status
if (reqfor.vip=='true') {
//style object is CSSStyleDeclaration, style names are not standard css names
// if (reqforLabel)
document.getElementById('label.request_item.request.requested_for').style.backgroundColor='red';
//change the requested for's name field to red text
// if (reqforField)
document.getElementById('sys_display.request_item.request.requested_for').style.color='red';
}
else {
//not a VIP, remove temporary styles
// if (reqforLabel)
document.getElementById('label.request_item.request.requested_for').style.backgroundColor='';
// if (reqforField)
document.getElementById('sys_display.request_item.request.requested_for').style.color='';
}
}

11 REPLIES 11

Linda - I know this is searching back a few years, but we are trying to get this to work now.   Did you get the client script working?   Thank you!


I figured out the solution.



Client Script


Type: onLoad


Table:   Catalog Task [sc_task]



function onLoad() {


var reqfor = g_form.getReference('request_item.request.requested_for');


var reqforLabel = document.getElementById('label.sc_task.request_item.request.requested_for');


var reqforField = document.getElementById('sys_display.sc_task.request_item.request.requested_for');


if (reqfor.vip == 'true'){


  document.getElementById('label.sc_task.request_item.request.requested_for').setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: "95% 55%"});


  document.getElementById('sys_display.sc_task.request_item.request.requested_for').style.color='red';


}else {


  document.getElementById('label.sc_task.request_item.request.requested_for').style.backgroundImage='';


  document.getElementById('sys_display.sc_task.request_item.request.requested_for').style.color='';


}


}


Helpful script. For some reason, I am not able to get the VIP GIF against the callers name, only the red highlighted text appears.


Need to keep digging.


(Im using the exact script as above)


Figured out the VIP GIF not displaying:


Add the following   .down('label') on line 3:


var reqforLabel = document.getElementById('label.sc_task.request_item.request.requested_for').down('label');


Similarly, for Requests:



Client Script


Type: onLoad


Table:   Request [sc_request]




function onLoad() {  


var reqfor = g_form.getReference('requested_for');  


var reqforLabel = document.getElementById('label.sc_request.requested_for');  


var reqforField = document.getElementById('sys_display.sc_request.requested_for');  


if (reqfor.vip == 'true'){  


  document.getElementById('label.sc_request.requested_for').setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: "15% 35%"});  


  document.getElementById('sys_display.sc_request.requested_for').style.color='red';  


}else {  


  document.getElementById('label.sc_request.requested_for').style.backgroundImage='';  


  document.getElementById('sys_display.sc_request.requested_for').style.color='';  


}  


}



...and for Items:



Client Script


Type: onLoad


Table:   Requested Item [sc_req_item]



function onLoad() {  


var reqfor = g_form.getReference('request.requested_for');  


var reqforLabel = document.getElementById('label.sc_req_item.request.requested_for');  


var reqforField = document.getElementById('sys_display.sc_req_item.request.requested_for');  


if (reqfor.vip == 'true'){  


  document.getElementById('label.sc_req_item.request.requested_for').setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: "15% 35%"});  


  document.getElementById('sys_display.sc_req_item.request.requested_for').style.color='red';  


}else {  


  document.getElementById('label.sc_req_item.request.requested_for').style.backgroundImage='';  


  document.getElementById('sys_display.sc_req_item.request.requested_for').style.color='';  


}  


}