How to set vip flag based on the users band on incident record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:25 PM
Hello
on users table record we have a reference field band.
on incident record callers band is A or A+ then we have to set vip flag on incident caller field. i tried with (g_form.getDisplayBox, g_form.getDisplayValue) but it is not working.
can anyone please help me to fix this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:31 PM
Hi @Arun61
To set the VIP flag on the Caller
field in the Incident form using a client script in ServiceNow, you can use a script that checks if the caller is marked as a VIP and then sets a visual indication (such as highlighting the field or showing a message). Apply your condition here.
Here's an example of a Client Script that sets the VIP flag:
Client Script Example:
- Script Type: OnChange
- Field: Caller (caller_id)
- Table: Incident
(function executeChangeControl(current, previous /*null when async*/) {
// Get the sys_id of the selected caller
var callerId = g_form.getValue('caller_id');
if (callerId) {
// Call GlideAjax to check if the caller is a VIP
var ga = new GlideAjax('VIPChecker'); // VIPChecker is a Script Include that you create
ga.addParam('sys_id', callerId);
ga.getXMLAnswer(function(response) {
var isVip = response.responseXML.documentElement.getAttribute("answer");
// If VIP, highlight the field and show a message
if (isVip === 'true') {
g_form.setFieldStyles('caller_id', 'background-color', '#FFCC00'); // Change field background color
g_form.addInfoMessage('This caller is marked as VIP.');
} else {
g_form.setFieldStyles('caller_id', 'background-color', ''); // Remove any background color
g_form.clearMessages(); // Clear any previous messages
}
});
} else {
g_form.clearMessages(); // Clear any messages if no caller is selected
}
})(current, previous);
Step-by-Step Explanation:
- Client Script Type: Set this to
onChange
and attach it to theCaller
field (caller_id
). - GlideAjax Call: It sends a request to a server-side Script Include (
VIPChecker
) to check if the caller is a VIP. - Field Styling: If the caller is marked as a VIP, the script highlights the
Caller
field and shows a message to the user. If the caller is not a VIP, it clears the field styling and any displayed messages.
Script Include (Server-side code):
To create the VIPChecker
Script Include that the client script uses, follow this example:
var VIPChecker = Class.create();
VIPChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isVIP: function() {
var callerId = this.getParameter('sys_id');
var user = new GlideRecord('sys_user');
if (user.get(callerId)) {
return user.getValue('vip') == 'true'; // Check if the user has VIP set to true
}
return false;
}
});
Notes:
- Make sure the
VIP
field is available on thesys_user
table. - Adjust field styles or messages according to your UI preferences.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 12:15 AM
Hi @Arun61
You can set up a Business Rule on the sys_user table as below for your requirement :
Output -
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 12:34 AM
Check this out.
https://www.youtube.com/watch?v=vVAAn2iP358
Regards,
Musab