Email notification based on advanced condition

leslie8
Mega Expert

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;

  }

1 ACCEPTED SOLUTION

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:


____Jim_C_____.png



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.


View solution in original post

13 REPLIES 13

Matt Saxton - G
Kilo Guru

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


saritha9
Giga Expert

Hello Leslie,



I see a syntax error in your code. Instead of using !== use != or ==


Thanks I tried both of those already != and == do not work either.


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