Notification on security_admin Role Elevation

SM24
Giga Guru

Hi all,

I have a requirement  to trigger a notification to a specific group whenever a user elevates their role to security_admin.

 

Details (OOTB) :

 

  • When a user elevates their role to security_admin, a record is generated in the sysevent table with the event name security.elevated_role.enabled.
  • In this event record:
    • parm1 contains the user ID of the user who elevated the role.
    • parm2 contains the value security_admin.

Steps I’ve Taken:

1. Created Notification:

  • I created a notification with the Send When condition set to "Event is fired" and selected security.elevated_role.enabled as the event.

2. Advanced Condition Script:

  • To ensure the notification only triggers when the elevated role is security_admin, I added the following script in the Advanced Condition section:

 

function elevated() {
    var sysEventGr = new GlideRecord('sysevent');
    sysEventGr.addQuery('sys_id', event.name.toString());
    sysEventGr.query();
    if (sysEventGr.next()) {
        if (sysEventGr.parm2 == "security_admin") {
            gs.print(sysEventGr.parm2);
            return true;
        }
    }
}

 

 

I expected this script to check the sysevent table record and confirm that parm2 equals security_admin and trigger the notification.

Issue:

  • Although this script works when run as a background script, the notification itself does not trigger as expected when the role is elevated.

Could anyone suggest a solution or identify what might be missing here to get the notification to trigger as expected? Thanks in advance.

 

Regards,

SM

 

 

1 ACCEPTED SOLUTION

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @SM24 - I'm not sure your script will work as intended, but you can avoid the GlideRecord query altogether. Try this:

 

if (event.parm2 = 'security_admin') {
	answer = true;
} else {
	answer = false;
}

 

View solution in original post

1 REPLY 1

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @SM24 - I'm not sure your script will work as intended, but you can avoid the GlideRecord query altogether. Try this:

 

if (event.parm2 = 'security_admin') {
	answer = true;
} else {
	answer = false;
}