I need to send notifications based on the field's value on the case form

Abhishek Kumar5
Tera Contributor

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.

find_real_file.png

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:

find_real_file.png

 

 

 

Could you please help or suggest on this to achieve easily.

Any help on this is really appreciated.

Thank you,

Abhishek

 

 

3 REPLIES 3

Community Alums
Not applicable

Hi Abhishek Kumar  ,

Use an advanced condition to send a notification based on the current email record, changing field values, or system properties.

To send a notification using an advanced condition, you can:
  • Call a function that returns a value, or
  • Set the global variable answer using a script
For example, in the following code, you call a function to prevent the system from sending an email notification if the sender of a self-service request is a member of the XYZ group:
(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.

The advanced condition script uses the following business rule global variables:
  • 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

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

Abhijit4
Mega Sage

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

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP