- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
THE PROBLEM WITH OOB CAPABILITIES
Those of you who've had rigorous testing protocols on ServiceNow know that there's a critical weakness with notification handling on non-production systems. You have only three options:
- Disable all notifications - "Great, now I can't test notifications at all!"
- Enable all notifications - "Great, now my customers get notifications they neither want nor expect" x2
- Send all notifications to specified email addresses - "Great, now my testers have to separate signal from noise"
There must be a better way.
SOLUTION: FILTER INTENDED RECIPIENTS
We need a solution that provides the following
- Req1 - authorize whole groups to receive notifications on non-prod
- Req2 - authorize single users to receive notifications on non-prod
- Req3 - exists on all instances, but only works on non-prod instances
We'll provide this solution with one dictionary entry and one before-insert business rule.
First, we build a true/false field named u_subprodemail on the Group table only. You might look at Req2 and say "don't we need this on User table too"? Nope! We're solving two use cases here. First is flagging whole groups that want to receive notifications. For individuals, we'll simply create a new group (with u_subprodemail = true) that we can put those 'one of' users in.
Now we create a Before Insert business rule on the Sys_Email table. We're going to intercept outbound email and bend it to our will!
NAME: Control Sub-Prod Email
CONDITION:
gs.getProperty('glide.servlet.uri') != "https://<yourinstancename>.service-now.com" && current.type != "received"
SCRIPT:
function onBefore(current, previous) {
var validSends = [];
var ga = new GlideAggregate('sys_user_grmember');
ga.addQuery('group.u_subprod_email',true);
ga.groupBy('user');
ga.query();
while (ga.next()){
if (current.recipients.indexOf(ga.user.email.toString()) >= 0){
validSends.push(ga.user.email.toString());
}
}
current.recipients = validSends.toString();
current.body = "SENT FROM NON-PRODUCTION SYSTEM \n\n" + current.body;
gs.log(gs.getProperty('glide.servlet.uri') + " " + validSends, 'Sub-Prod Notifications');
}
SCRIPT EXPLAINED
- We declare validSends variable as a blank array.
- We query the sys_user_grmember table finding all group members for groups that have the u_subprod_email set to true.
- We're using GlideAggregate and GroupBy so that multiple memberships with the same User are represented only once.
- For each result we compare the group member's email against the list of recipients targeted for the sys_email insert.
- If there's a match, we push the value to the validSends array.
- After we've tested all validated addresses, we overwrite current.recipients with validSends.
- We also add text to the top of the email body to reinforce it was sent from a non-prod system.
- REMEMBER: Because we're checking *group memberships* to groups that have been flagged as enabled, you may have users part of multiple groups, only one which is email enabled. A user only needs one "enabled" membership to receive all email targeted at them.
CONGRATULATIONS!
- You can include notifications as a component of your UAT.
- You can precision control the groups and users to receive those notifications.
- You can push this customization to prod so you don't have to rebuild it after every clone-back.
- 5,099 Views
- « Previous
-
- 1
- 2
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
