- 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 03:29 PM
Correct, but Leslie's requirement is such that the email notification will be sent if getJournalEntry(1) does not contain "email client message sent".
I'm going to make an assumption the Leslie has an email notification that has something along the lines of:
- When: Comments changes
- Leslie would include the script she is working on, such that if getJournalEntry(1) contains the string, the notification is not sent.
I guess it depends on Leslie's requirements, and whether the last update was a comment made or not (as well as not containing the string), versus something like what I described above where the email is sent as long as the last comment did not contain the string in question (regardless of if it was the most recent update).
Hopefully Leslie can clarify this for us!
- 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-10-2015 06:18 AM
Wow you guys are great! Yes, that is my requirement. The script that Jim has made is the exact answer I needed. Basically I just needed that journal entry field to evaluate the latest comment.
The condition comments.changes() is in my condition builder.
Thanks so much!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 09:13 AM
Hello Jim
This is great - but a question question.
I would like to apply this condition on a Business Rule, not a Notification.
I can't seem to get the formatting correct. Could you take a look? The business rule resides on the sc_req_item and on sc_task.
I do not want the business rule to fire (purpose: query related sc_tasks and update their comments field) if the comment update includes a specific string, just like you're doing in the condition here. Just can't get it formatted so that it works.
thank you!