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 07:49 AM
Hi,
Are you sure you have set Isolate Script field is false for your client script?
are you sure requested_for on form is dot walked from REQ only?
Because I tried the same and it worked for me.
what came in alert for answer?
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;
alert(answer);
//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 08:39 AM
Thanks for persevering with this, it's much appreciated.
I checked the client script and isolate script is definitely false. Having checked the form layout I could see that the Requested For was dot walked from request_item. However, adding it in from just request did nothing (existing in green, added in yellow):
I tried the new script you shared but no alert is generated, I assume this means that it isn't getting that far (or doesn't match the condition)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 09:36 AM
I've had a reply on another thread that has now fixed this, the script is as follows:
function onLoad() {
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;
/*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 = $('sys_display.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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 02:50 PM
the last script didnt work either.