Highlight Incidents | if callers are in special groups

Simon41
Giga Contributor

Hi,

at the moment we have a Client Script which highlights Incidents when the Caller or the "Affected User" (u_affected_user) is VIP oder IT. At the moment we use fields in the sys_user table to indicate this. 

Now we want to check if the caller is member of group "ROLE_A" or "ROLE_B" and if yes then highlight the incident. Is this possible?

Here is our current Client-Script. Thanks!

// This script highlights the VIP and IT users and keyuser near the field 'Affected User' on the incident table with a small image respectively and highlights the user name in that field in that respective color.

function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.incident.u_affected_user');
var callerField = $('sys_display.incident.u_affected_user');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('u_affected_user', vipCallerCallback);
}

function vipCallerCallback(caller) {
var callerLabel = $('label.incident.u_affected_user').down('label');
var callerField = $('sys_display.incident.u_affected_user');
if (!callerLabel || !callerField)
return;

//check for VIP status
if (caller.vip == 'true' || caller.u_it_user == 'true') {

if (document.documentElement.getAttribute('data-doctype') == 'true')
//bgPosition = "55% 45%";
if(caller.vip == 'true' && caller.u_it_user == 'true'){
var bgPosition = "30% 45%";
var bgPosition1 = "60% 70%";
callerLabel.setStyle({backgroundImage: ["url(VIPUSER.png)","url(IT.png)"], backgroundRepeat: ["no-repeat","no-repeat"], backgroundPosition: [bgPosition,bgPosition1]});
callerField.setStyle({color: "red"});
}else if(caller.vip == 'true'){
var bgPosition2 = "30% 45%";
callerLabel.setStyle({backgroundImage: ["url(VIPUSER.png)"], backgroundRepeat: ["no-repeat"], backgroundPosition: [bgPosition2]});
callerField.setStyle({color: "red"});
}else if(caller.u_it_user == 'true'){
var bgPosition3 = "30% 45%";
callerLabel.setStyle({backgroundImage: ["url(IT.png)"], backgroundRepeat: ["no-repeat"], backgroundPosition: [bgPosition3]});
callerField.setStyle({color: "red"});
}

} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}

 

1 ACCEPTED SOLUTION

Hi,

You would need to configure BR as below,

find_real_file.png

You can check if caller is member of particular group or not by writing below script in BR(change group name as per your need).

find_real_file.png

Access scratchpad object in client script as shown below and perform your further task.

find_real_file.png

Please mark as Correct or Helpful if it helps.

Thanks and Regards

Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

4 REPLIES 4

Abhijit4
Mega Sage

Hi,

Yes, it is possible.

You can write Display BR to check if caller is member of group ROLE_A or ROLE_B and you can store result in scratchpad object then you can access the same scratchpad object in client script and perform further operation as per your need.

Let me know if you have any further question.

Please mark as correct or helpful if it helps.

Thanks and Regards

Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Simon41
Giga Contributor

Hi Abhijit,

do you have an example how to implement this?

What must be in the BR and how can I access it from the Client Script?

Thanks!

Hi,

You would need to configure BR as below,

find_real_file.png

You can check if caller is member of particular group or not by writing below script in BR(change group name as per your need).

find_real_file.png

Access scratchpad object in client script as shown below and perform your further task.

find_real_file.png

Please mark as Correct or Helpful if it helps.

Thanks and Regards

Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Sushma R1
Tera Expert

You can use g_form.getLabel("caller_id") and g_form.getElement("sys_display.incident.caller_id") to access the field and labels, from there you can change the style attribute

 

As an example

 

 

 

var callerIDField = g_form.getElement("sys_display.incident.caller_id")

 

callerIDField.style="color: blue;"

 

 

 

Note: You should also be able to use Field Styles for the field CSS. Define field styles

 

Hit helpful if it was 🙂