- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 06:10 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 07:47 AM
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
I was expecting to achieve something like this with the colour red in the background
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
}
}
}```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 06:25 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 06:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 06:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 07:47 AM
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
I was expecting to achieve something like this with the colour red in the background
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
}
}
}```