Display VIP Flag on REQ and RITM and SC_task and caller filed need be red.

samanth
Tera Contributor

Hi All, 

 

I got a requirement to display the VIP flag on REQ and RITM and SC_task. I am able to achieve VIP flag and field color red on the REQ form it was working fine. On RITM and SC_task form i am able to see the VIP but the field color was showing black.   

The below same code was working in PDI instance and both are same versions san- Diego 

Below is the code for REQ 

sc_request table ->  on change  ( The code is working of REQ with out any issue)

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

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

function vipCallerCallback(caller) {
var callerLabel = $('label.sc_request.requested_for').down('label');
var callerField = $('sys_display.sc_request.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: ""
});
}
}

It was working on REQ 

find_real_file.png

---

SC_req_item  - client script  on before 

function onLoad() {

var callerLabel = $('label.sc_req_item.request.requested_for');

var callerField = $('sys_display.sc_req_item.request.requested_for');
// var callerField = $('sys_display.sc_req_item.request.requested_for').style.color = 'red';

if (!callerLabel || !callerField)

return;

/*if (!newValue) {

callerLabel.setStyle({backgroundImage: ""});

callerField.setStyle({color: ""});

return;

}*/

g_form.getReference('request.requested_for', vipCallerCallback);

}

function vipCallerCallback(caller) {

var callerLabel = $('label.sc_req_item.request.requested_for').down('label');

var callerField = $('sys_display.sc_req_item.request.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: "blue"});
//callerField.style.color='red';
//g_form.getControl('callerField').style.color = 'red';
//callerField.setStyle.backgroundColor='red';
callerField.setStyle({
color: "red"
});


} else {
callerLabel.setStyle({
backgroundImage: ""
});
callerField.setStyle({
color: ""
});

}
}

find_real_file.png

 

SC_TASK table - On before 

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

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

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

function vipCallerCallbackREQ(caller) {

var callerLabel = $('label.sc_task.request_item.request.requested_for').down('label');
var callerField = $('sc_task.request_item.request.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: ""
});
}
}

 

Style - 

find_real_file.png 

4 REPLIES 4

Musab Rasheed
Tera Sage

Hello,

Below threads have working code, Please tweak accordingly

https://community.servicenow.com/community?id=community_question&sys_id=a2bcb5a31b479090305fea89bd4bcb2b

https://community.servicenow.com/community?id=community_question&sys_id=0af0c70e1ba3c114b09633f2cd4bcb29

Mark my answer as correct if that helps.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab Rasheed, 

 

Already tied this solution but still it was not working, It is wired think in PDI the same code is working. 

 

Regards,

Samanth Reddy

 

Hi Musab Rasheed, 

 

I have tried from the above link still it was not working. 

 

Regards,

Samanth Reddy

 

Can you paste code again ?

Use {;} to insert code, that will be easy to check

Please hit like and mark my response as correct if that helps
Regards,
Musab