
- 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-18-2015 08:04 AM
Thank you for taking the time to reply. I tried your code, but both Marketing and the requester kept getting the notifications.
I opted for fixing my code as Gurpreet Singh pointed out.
Thanks again for your reply.
Rick Forristall
Goodwill of Central Arizona

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2015 08:00 AM
Gurpreet Singh - thanks for finding this. I looked at this code many, many times and didn't see that.
I appreciated you finding this problem in my code.
It is working now!
Thanks again,
Rick Forristall
Goodwill of Central Arizona