I need to send notifications based on the field's value on the case form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 11:39 PM
Hi,
I need to send email notification based on the certain condition specified on the two fields ( email, other email ) present on the case form.
table : Cases
we have Contacts(reference to customer_contact) field on the case form which contains both fields "Email" and "Other Email".
i.e.
Scenarios for Notification:
1) if the Email is provided and Other email is not provided , then communication needs to be sent to Email.
2) If the Email and Other email are provided then the communication needs to be sent to Other email.
3) IF both the Email and Other email are same then the communication needs to be sent to Email.
Existing email notification:
Could you please help or suggest on this to achieve easily.
Any help on this is really appreciated.
Thank you,
Abhishek
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2022 11:51 PM
Hi Abhishek Kumar ,
Use an advanced condition to send a notification based on the current email record, changing field values, or system properties.
- Call a function that returns a value, or
- Set the global variable
answer
using a script
(function() { var groupMember = gs.getUser(); return !groupMember.isMemberOf('XYZ'); })();
Alternatively, you can script the same advanced condition by using the answer
variable:
var groupMember = gs.getUser(); if(groupMember.isMemberOf('XYZ')){ answer = false; } else { answer = true; };
Note that the script must set the answer
variable to true to send the notification. If you script no conditionals, the value of answer
is equal to the last value that you set for the variable.
You can add a script-based condition in the Advanced condition field by configuring the Email Notification form and adding the field. You can access the field in the Advanced view without configuring the form.
- current: contains the current record from the table to which the notification is linked.
- event: contains the event that triggered the notification.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 03:17 AM
Hi,
Thank you for the response!
I've used email script to compare two email addresses value of two fields present on the contact which is on the Cases form.
But, script is not able to compare two email addresses.
Cond: if email addresses are same, then email need to be sent to "Email" field value as a recipient but not in CC.
Table : Cases
Contact : reference field
e.g. Email : abc@gm.com, Other Email : xyz@df.com
Script :
var emailId = current.contact.email.toLowerCase();
var otheremailId = current.contact.u_other_email.toLowerCase();
gs.info("emailid1212:" + emailId); // emailid1212:abc@gm.com
gs.info("otheremailId1212" + otheremailId); // otheremailId1212:xyz@df.com
if (emailId == otheremailId) {
// not able to get inside this loop
email.addAddress("cc", current.contact.email, current.contact);
}
Could you please suggest on this.
Thanks,
Abhishek Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 03:41 AM
Hi Abhishek,
Based on your provided script, if email and other email id is not same then how could it go inside if condition.
Could you please elaborate what are you expecting with input/output.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP