How to create a script include and client script to identify vip caller (custom field)

Atheher Fathima
Mega Guru

Hi All, 

 

I have created a new choice field called u_vip with choices as "vip" and "v-vip" on sys_user table. How do i write a script include and a client script on incident table to identify if the user is a VIP or V-vip or a normal user. If user is a vip then i would like to have the background colour red and purple for a v-vip user.

 

Any help on this is greatly appreciated.

 

Thank you

 

1 ACCEPTED SOLUTION

Hi @Oliver Stammler ,

 

The client would prefer to have a single choice field rather than the checkbox. Thank you so much for the script. One last request is, i am trying to add a image inside this field however it seems not to be showing the single image.

this is the below image i see

AtheherFathima_1-1671464725501.png

I was expecting to achieve something like this with the colour red in the background

AtheherFathima_2-1671464785774.png

below is the modified code which i tried :

 

```

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('UserUtils'); // UserUtils is the script include name
ga.addParam('sysparm_name', 'getVIPStatus'); // getVIPStatus is the function in the script include that we're calling
ga.addParam('sysparm_caller', g_form.getValue('caller_id').toString()); // send caller sys_id to the script include

ga.getXML(VIPCallerParse);

// callback function for returning the result from the script include
function VIPCallerParse(response) {
var vipStatus = response.responseXML.documentElement.getAttribute("answer");

switch (vipStatus) {
case 'vip':
g_form.getElement("sys_display.incident.caller_id").style.backgroundImage = "url('6.png')", style.backgroundRepeat = "no-repeat", style.backgroundPosition = "98% 55%", style.paddingright = '20px', style.backgroundColor = 'aqua' ;

break;
case 'v-vip':
g_form.getElement("sys_display.incident.caller_id").style.backgroundColor = "green";
break;
default:
// do nothing
}

}

}```

 

View solution in original post

5 REPLIES 5

mattystern
Kilo Sage

Hi Atheher,

 

You should be able to edit the OOB "Highlight VIP Caller" to assist here (using insert & stay)

 

Replace the OOB  lines 33-44 under the "check for VIP status" comment to something similar to:

	if (caller.u_vip == 'vip') {
		callerField.setStyle({color: "red"});
	}
	else if (caller.u_vip == 'v-vip'{
		callerField.setStyle({color: "purple"});
	}
	else {
		callerField.setStyle({color: ""});
	}
}

 

I have removed the VIP icon stuff / background positioning used in the OOB script. Also note this is just psudocode which I haven't tested! Let me know if you have additional questions.

Hi @mattystern ,

 

I was looking for creating a script include/function that i can use to call in different tables. this  OOB script is used for incident table alone, however we would like this functionality to show up across all tables for incident,tasks, requests etc.

Oliver Stammler
Giga Guru

Hey @Atheher Fathima,
quick question before answering your question: 
Wouldn't it be easier to create a "V-VIP" flag similiar to the out of the box vip flag on the sys_user table and then re-use the out of the box logic which already exists to highlight vip users? 

 

Nevertheless, here is the answer to your question.
OnChange-Script (field Caller) on incident table:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('UserUtils'); // UserUtils is the script include name 
	ga.addParam('sysparm_name','getVIPStatus'); // getVIPStatus is the function in the script include that we're calling 
	ga.addParam('sysparm_caller', g_form.getValue('caller_id').toString()); // send caller sys_id to the script include

	ga.getXML(VIPCallerParse);  	

	// callback function for returning the result from the script include
	function VIPCallerParse(response) {  
		var vipStatus = response.responseXML.documentElement.getAttribute("answer");

		switch(vipStatus) {
			case 'vip':
				g_form.getElement("sys_display.incident.caller_id").style.backgroundColor="red";
				break;
			case 'v-vip':
				g_form.getElement("sys_display.incident.caller_id").style.backgroundColor="green";
				break;
			default:
				// do nothing
		} 

	}

}

 

Script Include: 

var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getVIPStatus: function() {		
		var caller = this.getParameter("sysparm_caller");
		var grUser = new GlideRecord('sys_user');
		grUser.get(caller);

		return grUser.u_vip.toString();
	},
	type: 'GetUserInfo'
});

 

Best regards

Oli

Hi @Oliver Stammler ,

 

The client would prefer to have a single choice field rather than the checkbox. Thank you so much for the script. One last request is, i am trying to add a image inside this field however it seems not to be showing the single image.

this is the below image i see

AtheherFathima_1-1671464725501.png

I was expecting to achieve something like this with the colour red in the background

AtheherFathima_2-1671464785774.png

below is the modified code which i tried :

 

```

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('UserUtils'); // UserUtils is the script include name
ga.addParam('sysparm_name', 'getVIPStatus'); // getVIPStatus is the function in the script include that we're calling
ga.addParam('sysparm_caller', g_form.getValue('caller_id').toString()); // send caller sys_id to the script include

ga.getXML(VIPCallerParse);

// callback function for returning the result from the script include
function VIPCallerParse(response) {
var vipStatus = response.responseXML.documentElement.getAttribute("answer");

switch (vipStatus) {
case 'vip':
g_form.getElement("sys_display.incident.caller_id").style.backgroundImage = "url('6.png')", style.backgroundRepeat = "no-repeat", style.backgroundPosition = "98% 55%", style.paddingright = '20px', style.backgroundColor = 'aqua' ;

break;
case 'v-vip':
g_form.getElement("sys_display.incident.caller_id").style.backgroundColor = "green";
break;
default:
// do nothing
}

}

}```