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

mujahid2
Kilo Contributor

Since your current form is sc_task, use the following IDs
label.sc_task.request_item.request.requested_for and sys_display.sc_task.request_item.request.requested_for instead of label.request_item.request.requested_for and sys_display.request_item.request.requested_for.


Thank you for your response. I did try your suggestion and that also did not work. I have tried several variations of dot walking and nothing is working.


mujahid2
Kilo Contributor

I used the following script in the servicenow demo site (demo.servicenow.com):



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');

console.log(reqfor);


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


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


}


This works fine in the demo site. I have attached an update set that was done in the demo site. So you can check in the demo site.[asset|aid=964|format=link|formatter=asset|title=SC_TASK_Client_Script]

Did you try testing your script without if conditions.

Remove console.log(reqfor); if you are not using firebug to debug.


lindac
Kilo Explorer

Thank you for your response, but that also did not work. I have tried several variations of dot walking and nothing is working.