
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2015 08:53 PM
Good day,
I have a notification that needs to be sent when a field is updated. This field is updated two ways. (1) By the marketing team inside a form view and (2) by an inbound email action when the customer replies to an email sent by ServiceNow.
When the field is updated by method 2 I need to ensure only the Marketing folks get notified. So in the advanced Condition script I'm trying to do this:
1. When the field is updated and
2. If the person who updated the field is NOT in the GICA Marketing group.
The problem is whenever the user replies and the field gets updated both the user AND marketing gets notified.
Here's the script I'm using - can anyone help?
I think the problem I'm having is related to trying to see if the updated by field is in the group.
Thanks in advance for any assistance,
Rick Forristall
Goodwill of Central Arizona
======================= SCRIPT BELOW ==========================
// only send this email notification to Marketing if the updated by person is NOT in marketing
if (current.u_customer_communications.changes() && !isGroupMember(current.sys_updated_by, 'GICA Marketing') ) {
answer = true;
} else {
answer = false;
}
function isGroupMember(user, groupName) {
var good_user = false;
var good_group = false;
// does the user exist?
var usrGr = new GlideRecord('sys_user');
usrGr.addQuery('user_name', user);
usrGr.query();
if (usrGr.next() ) {
userID = usrGr.sys_id + '';
good_user = true;
}
// does the group exist?
var grpGr = new GlideRecord('sys_user_group');
grpGr.addQuery('name', groupName);
grpGr.query();
if (grpGr.next() ) {
groupID = grpGr.sys_id + '';
good_group = true;
}
if (good_user && good_group) {
//Now see if they are a member of the group
var grpMbr = new GlideRecord('sys_user_grmember');
grpMbr.addQuery('user', userID);
grpMbr.addQuery('group', groupID);
gr.query();
if (gr.next()) {
return true;
} else {
return false;
}
} else {
return false;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2015 10:04 PM
In last GlideRecord you are using variable grMbr but you made queries gr.query() and gr.next() .
use grMbr.query() and grMbr.next().
Also according to me you just need to use the third glide record because sys_user_grmember table will have the record only if user and group exists in their respective tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2015 10:04 PM
In last GlideRecord you are using variable grMbr but you made queries gr.query() and gr.next() .
use grMbr.query() and grMbr.next().
Also according to me you just need to use the third glide record because sys_user_grmember table will have the record only if user and group exists in their respective tables.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2015 11:49 PM
Hi Richard,
My suggestion on this, Create new email notification but use same template.
From inbound action fire the event.
Regards,
Harish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2015 08:02 AM
Thank you for your reply. I like your idea, but I wanted to keep all the information in one location -- the notifications.
Thanks again,
Rick Forristall
Goodwill of Central Arizona

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2015 02:16 AM
This 2 line equivalent code should do the job for you
var currentUser = gs.getUser().getUserByID(current.sys_updated_by);
return (currentUser.isMemberOf('GICA Marketing'));
Please click on the Correct Answer and/or Helpful Answer buttons if the response helps. This helps other users to see that a valid response was received.