how to send mail based on field value changes?

Posted by Sudhakar on 06-Oct-2014 16:50

Hi all,
As shown below image "Loan Cannot Be Sold To (Approved):" and "Loan Cannot Be Sold To (CTC):" are two Group of check boxes,if the user changes values in the above two fields,i need to send the mail as below 

Hi client
the list of fields changed:

Loan Cannot Be Sold To (Approved): //we need to include this field if there is change in this field while saving record

Loan Cannot Be Sold To (CTC)://we need to include this field  if there is change in this field while saving record

Thanks,
Support Team.



if none of the field changed no need to to send mail.

Kindly let me know how can achieve the above.

All Replies

Posted by Gian Torralba on 06-Oct-2014 17:18

Hi Sudhakar,

Please follow this steps:

1. Create two text fields that will hold the previous value of those group check box fields.

2. Create an after update trigger that will update the newly created fields.

The trigger should contain a code somewhat similar to this:

return "{!group_cb#value}" /*if the value is an array, use javascript join() method to join the arrays into a string*/

3. Create a send email after update trigger that has a condition similar to this:

var newVal = "{!group_cb#value}";

newVal = newVal.join(",");

var prevVal = "{!prev_cb#value}";

 

var newVal2 = "{!group_cb_2#value}";

newVal2 = newVal2.join(",");

var prevVal2 = "{!prev_cb_2#value}";

 

if(newVal != prevVal || newVal2 != prevVal2)

 return true;

4. Create a formula field that will be inside the email template. This will contain the dynamic value of those check boxes that needs to be displayed. Please follow this sample code:

var newVal = "{!group_cb#value}";

newVal = newVal.join(",");

var prevVal = "{!prev_cb#value}";

 

var newVal2 = "{!group_cb_2#value}";

newVal2 = newVal2.join(",");

var prevVal2 = "{!prev_cb_2#value}";

 

var outputText = '';

if(newVal != prevVal)

 outputText += "Loan Cannot Be Sold To (Approved)";

if(newVal2 != prevVal2)

 outputText += "Loan Cannot Be Sold To (CTC)";

return outputText;


5. The trigger hierarchy should be like this:

- 1. Send Email

- 2. Update previous field value


Hope this helps. Let me know if you have any questions.

Thank you,

Gian

Posted by Sudhakar on 07-Oct-2014 12:32

perfect,helps me a lot,thank [mention:c5dec1ce5a5948c5a25cf4bcaeb7db77:e9ed411860ed4f2ba0265705b8793d05] ...

This thread is closed