How to set vip flag based on the users band on incident record

Arun61
Tera Contributor

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

Arun61_1-1728541417000.png

 

 

3 REPLIES 3

PrashantLearnIT
Giga Sage

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:

  1. Script Type: OnChange
  2. Field: Caller (caller_id)
  3. 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:

  1. Client Script Type: Set this to onChange and attach it to the Caller field (caller_id).
  2. GlideAjax Call: It sends a request to a server-side Script Include (VIPChecker) to check if the caller is a VIP.
  3. 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 the sys_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
********************************************************************************************************

Amit Verma
Kilo Patron
Kilo Patron

Hi @Arun61 

 

You can set up a Business Rule on the sys_user table as below for your requirement :

 

AmitVerma_0-1728544468515.png

 

AmitVerma_1-1728544481912.png

 

Output -

AmitVerma_2-1728544504911.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Musab Rasheed
Tera Sage
Tera Sage

Check this out.

https://www.youtube.com/watch?v=vVAAn2iP358

Please hit like and mark my response as correct if that helps
Regards,
Musab
See our ServiceNow services here: https://www.beyond20.com/servicenow-consultation See our Cherwell services here: https://www.beyond20.com/cherwell-consulting Digital Transformation Blog: https://www.beyond20.com/blog/ beyond20.com