AnsweredAssumed Answered

How can I update a lead's related calls via logic hook?

Question asked by Shad on Apr 17, 2014
Latest reply on Apr 17, 2014 by Jason Eggers
Trying to update related calls to Leads with a logic hook. I want to assign a time zone to the lead and related calls record. I have it working fine using a direct SQL update. Was trying to get it to work using the built in functions though and just couldn't get it to work.



Code below. I commented out what I was attempting to do using get_linked_beans.
Using CE 6.5.10

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: smickelberry
 * Date: 4/16/14
 * Time: 12:55 PM
 
 */

class timeZone {
    function timeZone(&$bean, $event, $arguments) {
        include('/var/www/includes/shadFormFunctions.php');
        global $current_user, $db;
       $state = $bean->primary_address_state;

        /**
         * Return the time zone from an array with States and State codes
         */

        $zone = time_zone_return($state);

        //Probably a typo if we didn't get anything returned
       // For now that is the users fault so we won't update it.
        if (strlen($zone) == 0){
            return FALSE;
        }
        /**
         * Using beans
         *
         * $calls = $bean->get_linked_beans('calls', 'Call');
         * foreach($calls as $call){
         *      $call->time_zone_c = $zone;
         *          * }
         *
         */
        $bean->time_zone_c = $zone;
        $lead_id = $bean->id;
        $sql = "UPDATE calls_cstm  AS cc INNER JOIN calls AS c on c.id = cc.id_c INNER JOIN leads as l on l.id = c.parent_id SET cc.time_zone_c = '$zone'
        WHERE c.deleted = 0 AND c.status= 'Planned' AND l.id = '$lead_id'";
    //    $result = $db->query($sql);
    }
}

?>

Outcomes