VIP flag on catalogue tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:46 AM
Hi all
I've had a request to add VIP flags for Requests, Requested Items and Catalog Tasks. I've searched the forums and found the following article:
Following the advice and examples in the post, I have been able to get the flag to show on the list view for Requests, Requested Items and Tasks, and on the record view for Requests and Requested Items (requested for name is in red and VIP flag shows to the left of the field).
Can anyone help me to get the flag showing on the Task records?
For completeness this is what I have currently got set up:
Client Script, table = sc_request, isolate script unchecked:
function onLoad() {
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', vipCallerCallbackREQ);
}
function vipCallerCallbackREQ(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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Client Script, table = sc_req_item, isolate script unchecked:
function onLoad() {
var callerLabel = $('label.sc_req_item.request.requested_for');
var callerField = $('sys_display.sc_req_item.request.requested_for');
if (!callerLabel || !callerField)
return;
/*if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}*/
g_form.getReference('request.requested_for', vipCallerCallbackREQ);
}
function vipCallerCallbackREQ(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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Client Script, table = sc_task, isolate script unchecked:
function onLoad() {
//Type appropriate comment here, and begin script below
var callerLabel = $('label.sc_task.request_item.request.requested_for');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
var number = g_form.getUniqueValue();
var ga = new GlideAjax("isVIP");
ga.addParam("sysparm_name", "vip");
ga.addParam("sysparm_numnber", number);
ga.getXML(vipCallBack);
}
function vipCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var callerLabel = $('label.sc_task.request_item.request.requested_for').down('label');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
//check for VIP status
if (answer == '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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Script Include, Client Callable checked:
var isVIP = Class.create();
isVIP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
vip: function(){
var number = this.getParameter('sysparm_numnber');
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", number);
gr.query();
if (gr.next()) {
return gr.request.requested_for.vip;
}
},
type: 'isVIP'
});
Style:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:51 AM
Hi,
you should update the onLoad client script on sc_task
function onLoad() {
//Type appropriate comment here, and begin script below
var callerLabel = $('label.sc_task.request_item.request.requested_for');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
var number = g_form.getValue('request_item');
var ga = new GlideAjax("isVIP");
ga.addParam("sysparm_name", "vip");
ga.addParam("sysparm_numnber", number);
ga.getXML(vipCallBack);
}
function vipCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var callerLabel = $('label.sc_task.request_item.request.requested_for').down('label');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
//check for VIP status
if (answer.toString() == '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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 04:12 AM
Thanks for the reply Ankur
Unfortunately, that has made no difference, the flag does not show next to the Requested For field on the Task record and the name is not highlighted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 05:15 AM
Hi,
the requested_for on sc_task comes from request field and not request_item
so update script as this and don't dot walk on request_item
check the changes in bold
function onLoad() {
//Type appropriate comment here, and begin script below
var callerLabel = $('label.sc_task.request_item.request.requested_for');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
var number = g_form.getValue('request_item');
var ga = new GlideAjax("isVIP");
ga.addParam("sysparm_name", "vip");
ga.addParam("sysparm_numnber", number);
ga.getXML(vipCallBack);
}
function vipCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var callerLabel = $('label.sc_task.request.requested_for').down('label');
var callerField = $('sys_display.sc_task.request.requested_for');
if (!callerLabel || !callerField)
return;
//check for VIP status
if (answer.toString() == '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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 07:10 AM
Hi
I was aware of the source of Requested For but thank you for the extra information. I have tried that new script and it is still not updating the Task record with the flag.
When looking at the task record this is all I see:
This is working on the list view for tasks so not sure why it isn't pulling through on the record itself!