How can we show the VIP flag for the "Requested for" field on the form?

Bill_Ymr_61
Mega Guru

We have been asked to show the VIP flag for requests, similar to what shows for incidents.  We have been able to create a style that shows the VIP gif in the list, but we are having trouble getting the gif to show on the forms.  Below is the client script that we tried to use, but still not getting the gif to show.

We are currently using London Patch 4

This is the form of the script:

find_real_file.png

This is the script:

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', 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' });
   //set callerField color
   callerField.setStyle({color: "red"});
   } else {
   callerLabel.setStyle({backgroundImage: ""});
   callerField.setStyle({color: ""});
   }
}

1 ACCEPTED SOLUTION

Here are the scripts for REQ and sc_task

 

Request client script

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

 

Catalog task client script

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

}

 

We also need to make some changes to script include and sc_req_item client so that single script include fits for sc_task as well. Please update the below lines in earlier scripts

Script include update

gr.addQuery("sys_id", number);

Client script update

var number = g_form.getUniqueValue();

 

View solution in original post

26 REPLIES 26

Is Isolate script field set to false?

Is the client script created on sc_req_item table?

Is the Client callable set to true on script include?

I thought I replied earlier, but I don't see it here.

The answer to all 3 questions is "Yes".

I was incorrect earlier, your script does show the VIP flag on the RITM screen, but not the other 2.

Here are the scripts for REQ and sc_task

 

Request client script

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

 

Catalog task client script

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

}

 

We also need to make some changes to script include and sc_req_item client so that single script include fits for sc_task as well. Please update the below lines in earlier scripts

Script include update

gr.addQuery("sys_id", number);

Client script update

var number = g_form.getUniqueValue();

 

That did it.  I now have the flags on all 3 forms.  Thank you for all the help!!

ack
Tera Contributor

HI Dvp ,

 

It really helped me ..

 In my case i have to check 5 types of users (i.e VIP , EX VIP AND SENSITIVE etc ..)  all are important user for us .

so could you please help , its really urgent . 

 

Thanks in advance ....