Query not return any result in logic hook but query work in MySQL workbench

My code in Cases module hook:

$sql = "select c.id from cases c
        left join emails e on e.parent_id = c.id and e.parent_type = 'Cases'
        left join emails_text et on et.email_id = e.id
        where c.id = '{$focus->id}' and et.to_addrs like '%_string_%'";
$result = $focus->db->query($sql,true);
$check =  $focus->db->fetchByAssoc($result);
if(!empty($check)){
     $GLOBALS['log']->fatal("Hello World ".$check);
}

I search solution in google many people suggest to using SugarQuery but it not more complex for my query or I do wrong with my code?

Please suggest me for solution.

Sugar 7.6 Ent

Thanks,

M

Parents
  • Hi

    try this ...

    global $db;

    $res = $db->query(" YOUR QUERY");    

  • if(!emptyempty($check))

    emptyempty - this is error in your code or just typo in the message?

     

  • Hi Autchara Chaiprom,

    Can you paste the whole function of your code? so we could know if you are really getting the correct parameters.

    Thanks,

    Longki

  • When email incoming

    then create case but for some email address should be set to specify user 

    I create case hook(before save) to re-assigned to user.

    function schedule(&$focus, $event){

    if($focus->team_id == '_teamid_'){

                            unset($sql);

                            $sql = "SELECT c.name as 'cname' FROM cases c ".

                                    "LEFT JOIN emails e ON e.parent_id = c.id and e.parent_type = 'Cases' ".

                                    "LEFT JOIN emails_text et ON et.email_id = e.id ".

                                    "WHERE c.id = '{$focus->id}' AND et.to_addrs LIKE '%_emailaddr_%' ";

                            $check = $focus->db->query($sql,true);

                            while($row = $focus->db->fetchByAssoc($check)){

                                    $name = $row['cname'];

                                    $GLOBALS['log']->fatal("Get:  ".$row['cname']);

                            }

                            $GLOBALS['log']->fatal('Get: '.$name .' SQL: ' . $sql);

                            if(!empty($name)){

                                    $GLOBALS['log']->fatal('Yes');

                                    $focus->assigned_user_id = '_userid_';

                            }else{

                                    $GLOBALS['log']->fatal('Not set');

                            }

                    }

    }

    I copy sql in log then run in workbench Its work but when I try to fetch value from sql data always null

Reply
  • When email incoming

    then create case but for some email address should be set to specify user 

    I create case hook(before save) to re-assigned to user.

    function schedule(&$focus, $event){

    if($focus->team_id == '_teamid_'){

                            unset($sql);

                            $sql = "SELECT c.name as 'cname' FROM cases c ".

                                    "LEFT JOIN emails e ON e.parent_id = c.id and e.parent_type = 'Cases' ".

                                    "LEFT JOIN emails_text et ON et.email_id = e.id ".

                                    "WHERE c.id = '{$focus->id}' AND et.to_addrs LIKE '%_emailaddr_%' ";

                            $check = $focus->db->query($sql,true);

                            while($row = $focus->db->fetchByAssoc($check)){

                                    $name = $row['cname'];

                                    $GLOBALS['log']->fatal("Get:  ".$row['cname']);

                            }

                            $GLOBALS['log']->fatal('Get: '.$name .' SQL: ' . $sql);

                            if(!empty($name)){

                                    $GLOBALS['log']->fatal('Yes');

                                    $focus->assigned_user_id = '_userid_';

                            }else{

                                    $GLOBALS['log']->fatal('Not set');

                            }

                    }

    }

    I copy sql in log then run in workbench Its work but when I try to fetch value from sql data always null

Children