Want update a date field based on most recent email date

Want update a date field based on most recent email date

I want to automatically update a date field in a Contact when a new email is attached to that Contact. This is a field created for the Contact layout called "Last Outgoing Contact". I created a function to do this, but it doesn't appear to work.

  1. //access the emails field from the Contact
  2. emailInfo = zoho.crm.getRelatedRecords("Contacts","ID","Emails","Emails");
  3. //create a list of every email from that Contact
  4. emailList = emailInfo.get("Emails");
  5. //count the number of emails in that list
  6. count = emailList.size();
  7. //if the number of the emails in the list is greater than 0, get the most recent email's Created Time date
  8. if(count > 0)
  9. {
  10. mostRecentDate = emailList.get(0).get("Created Time");
  11. for each index i in emailList
  12. {
  13. if(emailList.get(i).get("Created Time") > mostRecentDate)
  14. {
  15. mostRecentDate = emailList.get(i).get("Created Time");
  16. }
  17. }
  18. // Update the Last Contact Date with that date
  19. put("Latest Outgoing Contact",mostRecentDate);
  20. }
  21. return;