- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 01:47 PM
I need to make a condition that does NOT send an email notification if the comments contains a certain string of text.
When the comments field contains the text "email client message sent" I do not want the notification to be sent. I have similar rules working for other advanced conditions.
I have this advanced condition but for some reason it is still sending the notification even when the comments contains the phrase "email client message sent".
var comments = current.comments;
if (comments.indexOf('email client message sent') !== -1) {
answer = false;
}
else {
answer = true;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 07:26 PM
Actually, you are correct. I should have tested out the "changes" condition (I know it did not work previously - I just tested in Fuji, Patch 4). So, a notification with the following condition and script should work, assuming we understand the requirements:
The script would be:
answer = (current.comments.getJournalEntry(1).toLowerCase().indexOf("email client message sent") == -1);
So like you said, the Condition field will first make sure a comment was added and then the script checks to see if the string is NOT found in the latest comment, setting the answer to "true" which would then trigger the email. I always like to force a compare on lowercased strings just to be safe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 01:56 PM
Hi Leslie,
I've never been a big fan of using anything but event conditions for emails. They are much easier to test and see working. By using events you can check with a business rule 1st and then trigger the email if you so desire. Here's the wiki article for on a guided howto.
Events and Email Notification - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 02:02 PM
Hello Leslie,
I see a syntax error in your code. Instead of using !== use != or ==
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 02:04 PM
Thanks I tried both of those already != and == do not work either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2015 02:10 PM
Check if the comments field is of type Journal Input or String. If it is of type journal input or journal check the following wiki url:
Using Journal Fields - ServiceNow Wiki