AnsweredAssumed Answered

Code works but receive a message "Can't connect with server" and the page doesn't reload.

Question asked by Marcel Lyyra on Aug 16, 2018

Hi,

 

I have the code below (also attached) that will verify conditions in Opportunities and save a value from a dropdown on a multiselect list (both lists are the same) on Contacts.

 

The code works (it includes the value on the Contact) but it will pop an error message saying "There was a connection error when trying to connect with server" and the page won't reload staying on edition mode.

 

Does anyone knows what could be the issue here?

 

The code:

 

<?php

if (!defined('sugarEntry') || !sugarEntry) die ('Not A Valid Entry Point');

require_once('include/SugarLogger/LoggerManager.php');

$GLOBALS['log']->fatal('---------- Começou o OPP_ADERIDA ----------');

class opp_aderida
{
function after_save_opp($bean, $event, $arguments)
{
if($bean->opportunity_type == 'ReceitaExisting' && $bean->sales_stage == 'Closed Won' && $bean->lftm_status_operacional_c == 'Concluida')
{

$id_opp = $bean->id;

$GLOBALS['log']->fatal('ID oportunidade: '. $id_opp);

$sql = "SELECT IFNULL(l1.id,'') l1_id

FROM opportunities
INNER JOIN contacts_opportunities_1_c l1_1 ON opportunities.id=l1_1.contacts_opportunities_1opportunities_idb
AND l1_1.deleted=0

INNER JOIN contacts l1 ON l1.id=l1_1.contacts_opportunities_1contacts_ida
AND l1.deleted=0

WHERE (((opportunities.id='" . $id_opp . "')))
AND opportunities.deleted=0;";

$conn = $GLOBALS['db']->getConnection();

//$GLOBALS['log']->fatal('Got Connection OPP_ADERIDA');

$stmt = $conn->executeQuery($sql);

//$GLOBALS['log']->fatal('Query executed OPP_ADERIDA');

$row = $stmt->fetch();

$estrategiarv = $bean->lftm_estrategia_rv_c; //swing

$GLOBALS['log']->fatal('estrategiarv: '. $estrategiarv);

$contact_bean = BeanFactory::retrieveBean('Contacts', $row['l1_id'], array('disable_row_level_security' => true));

$GLOBALS['log']->fatal('print ROW: '. print_r($row, true));
$GLOBALS['log']->fatal('ID Cliente: '. $row['l1_id']);

$aderidas = $contact_bean->lftm_estrategias_rv_c; // ^Buy^,^IPO^,^Hedge^

$GLOBALS['log']->fatal('aderidas: '. $aderidas);
$GLOBALS['log']->fatal('Contact_bean_name: '. print_r($contact_bean->name,true));

if($aderidas == "" || $aderidas == null || $aderidas == "^^")
{
$estrategia = "^" . $estrategiarv . "^"; //^swing^

$contact_bean->lftm_estrategias_rv_c = $estrategia;

$contact_bean->save();

$GLOBALS['log']->fatal('contact_bean->lftm_estrategias_rv_c: '. $contact_bean->lftm_estrategias_rv_c);

$GLOBALS['log']->fatal('Processing Contact: ' . $contact_bean->full_name);

return true;
}

else
{
$estrategia = ",^" . $estrategiarv . "^"; //,^swing^

$GLOBALS['log']->fatal('estrategia: '. $estrategia);


if(strpos($aderidas, $estrategiarv) === false) // se swing existe em ^Buy^,^IPO^,^Hedge^
{
$GLOBALS['log']->fatal('Entrou no IF');

$aderidas = $aderidas . $estrategia; //^Buy^,^IPO^,^Hedge^ + ,^swing^

$GLOBALS['log']->fatal('Nova aderidas: '. $aderidas);

$contact_bean->lftm_estrategias_rv_c = $aderidas;

$contact_bean->save();

$GLOBALS['log']->fatal('contact_bean->lftm_estrategias_rv_c: '. $contact_bean->lftm_estrategias_rv_c); //^Buy^,^IPO^,^Hedge^,^swing^

$GLOBALS['log']->fatal('Processing Contact: ' . $contact_bean->full_name);

return true;
}

else
{
$GLOBALS['log']->fatal('Entrou no ELSE');
return true;
}
}

$GLOBALS['log']->fatal('---------- Terminou o OPP_ADERIDA ----------');
}
}
}

 

Regards,

Attachments

Outcomes