/
5.21.4.3.1 - Sending an Email Upon Saving a Case
5.21.4.3.1 - Sending an Email Upon Saving a Case
This example shows an on save script that will send an email depending on the value of a specified field when the case is saved.
This example can be used by copying it out in to your system and changing the field ID and value to those of the field you wish to use
Script
// The first line specifies the custom field that will trigger the email when it is edited [Changed.CustomField(6342).Changed] // This defines that the function is triggered upon saving the case function on_save() { // Here you can specify which new value will trigger the system email, in this case "True" represents a ticked checkbox if (Changed.CustomField("6342").NewValueAsText == 'True') { // These function send the email using the specified template as well as displaying a success message Service.SendEmail('Confirmation Email'); Service.AddMessage('Your email - Confirmation Email - has been sent.','success'); // "return true" indicates that the new data will be saved to your system, "return false" signifies that the new data will not be saved return true; } // The "else" function indicates that the following code will fire when the value is not as specified else { Service.AddMessage('Sending your email failed, the value of field Scripting Example did not equal Send Email', 'success'); return true; } }
The code block above displays the script that you should use to write the script.
Positive result
If the box is checked then the script will generate a positive result, send the email and display this message.
Negative result
If the box is not checked, then the script will deliver a negative response and display this message, informing the user that the email could not be sent.