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 @Community Alums
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
onChangeand attach it to theCallerfield (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
Callerfield 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
VIPfield is available on thesys_usertable. - Adjust field styles or messages according to your UI preferences.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 12:15 AM
Hi @Community Alums
You can set up a Business Rule on the sys_user table as below for your requirement :
Output -
Thanks and Regards
Amit Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 12:34 AM