I'm sure you could use logic hooks for this. We wanted to check a checkbox anytime an email came in so we created two files in custom/modules/Emails:
logic_hooks.php (hook definition file):
PHP Code:
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(6, 'flag_new_email_history', 'custom/modules/Emails/NewEmailHistory.php','NewEmailHistory', 'flag_new_email_history');
?>
NewEmailHistory.php:
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class NewEmailHistory {
function flag_new_email_history(&$bean, $event, $arguments)
{
//$GLOBALS['log']->fatal("flag_new_email_history");
require_once('modules/Emails/Email.php');
require_once('modules/Cases/Case.php');
//get id...if not set then it is a new record so create an id here
if(empty($bean->id)) {
$bean->id = create_guid();
$bean->new_with_id = true;
}
/** for inbound emails */
if(isset($bean->parent_type) && $bean->parent_type == 'Cases' && !empty($bean->parent_id)
&& $bean->type != "archived" && strpos($bean->name,"[Case:") !== false
) {
//$GLOBALS['log']->fatal("setting new history flag");
/**
//triggers more logic hooks which we don't want so manually run the update query instead
$case = new aCase();
$case->retrieve($bean->parent_id);
$case->new_history_c = '1';
$case->save();
*/
require_once('include/utils.php');
global $db;
$query = "UPDATE cases_cstm SET new_history_c = '1' where id_c = '".$bean->parent_id."'";
$db->query($query,true,"Error seting email new history for case: ".$bean->parent_id);
}
}
}
?>
With some creativity you should be able to do what you need.
Bookmarks