VIP Flag on Requested Items and Tasks

Olly IB
Tera Contributor

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:

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

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:

find_real_file.png

1 ACCEPTED SOLUTION

Preston5
Giga Contributor

I've been working on this, but rather than use the script include and all the reformatting, I just adjusted the same script you used for request and request item. Looks like you just had the wrong traversals in a couple places. 

 

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: ""});
							}
   
}

 

 

View solution in original post

4 REPLIES 4

Olly IB
Tera Contributor

Edited with updates but would still appreciate some assistance.

Preston5
Giga Contributor

I've been working on this, but rather than use the script include and all the reformatting, I just adjusted the same script you used for request and request item. Looks like you just had the wrong traversals in a couple places. 

 

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: ""});
							}
   
}

 

 

Olly IB
Tera Contributor

Preston, you are a legend, that worked a treat, thank you so much!

samanth
Tera Contributor

Preston, you are legend.