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

Hi Rajinisree,

 

Thanks for your response.

 

As you suggested, it works and VIP flag is visible on before Requested for field in Request form however its text color is till showing in black instead of red.

And I copied the entire script from here only.

Any idea what is wrong? Isloate flag is set to false

You need to alter your script with your field_names

this part: callerLabel and callerField

function onLoad() {
   //Type appropriate comment here, and begin script below
   var callerLabel = $('label.sc_request.requested_for');
	var callerField = $('sys_display.sc_request.requested_for');
	if (!callerLabel || !callerField)
		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;

 

You need to know some javascript skills.