Trigger email notification when user has admin role, security admin and or import admin

Ponda
Tera Contributor

Hello all 

 

I am creating an email notification for when an export is done. 

 

I want this to only trigger if the user has an admin role such as admin, security_admin and import_admin

 

I have created my event and now creating the notification but not sure what to do with the condition to meet my requirement.

Please see screenshot for what I have done thus far, any help will be appreciated. 

Ponda_0-1700499796466.png

 

 

 

5 REPLIES 5

Dibyaratnam
Tera Sage

If the logged in user should have any of the roles mentioned above, use the Advanced condition field and add below script

answer = false;

if (gs.hasRole("admin") || gs.hasRole("security_admin") || gs.hasRole("import_admin")) {
    answer = true;
}

 

Please mark it as correct if it helps. Let me know incase of any issue.

Shubha_Prada
Tera Guru

Hello @Ponda,

You can try adding a script in the advanced condition of the notification similar to the script as shown below -

Shubha_Prada_0-1700500980315.png

 

Code for reference -

function userHasRole() {
var userGr = new GlideRecord("sys_user_has_role");
userGr.addQuery('user', current.session_user); //field on the record who will be the recipient
userGr.addQuery('role.nameINadmin,security_admin,import_admin');
userGr.query();
if (userGr.next()) {
return true;
} else
return false;
}

 

Please mark this solution as helpful if it helps you 🙂

 

Best Regards,

Shubha S

Jim Coyne
Kilo Patron

Where were you going to trigger the event from?  I would look at adding the condition in there and only raise the event if the condition is met.  No point raising the event if it does not and then checking it in the Notification to see if the email should go out.

Ponda
Tera Contributor

I am sorry, did not understand your statement Jim!

 

I created and event and I would expect the notification will contain the conditions. Are you saying to have the script within the BR

Ponda_0-1700508758218.png