AnsweredAssumed Answered

Problem - after_relationship_add - Create registry before SugarCRM

Question asked by Bruno Ribeiro on Sep 21, 2016
Latest reply on Sep 13, 2017 by Krunoslav Djakovic

Guys,

 

I have a problem with after_relationship_add, when I try create a contact record module for opportunity is returned error 500 server, but when I do the combination of a record in the opportunity not have problem.  Has anyone ever experienced this ?

 

But in my enviroment local  and production it's working. Only in the enviroment "box" that does not work.

 

Sorry my english. 

<?php

//custom/Extension/modules/Opportunities/Ext/LogicHooks/logic_hooks_setar_nome_aluno_referente_a_oportunidade.php

$hook_array['after_relationship_add'][] = Array(
//Processing index. For sorting the array.
1,

//Label. A string value to identify the hook.
'Vincular o nome do Aluno na Oportunidade',

//The PHP file where your class is located.
'custom/include/vincularnomealunonaoportunidade.php',

//The class the method is in.
'vincularnomealunonaoportunidade',

//The method to call.
'metodo_vincularnomealunonaoportunidade'
);

?>
<?php
//custom/include/vincularnomealunonaoportunidade.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/SugarQuery/SugarQuery.php');

class vincularnomealunonaoportunidade
{
function metodo_vincularnomealunonaoportunidade($bean, $event, $arguments)
{
//Previnindo de um Loop Logic Hooks
if (!isset($bean->ignore_update_c) || $bean->ignore_update_c === false)
{
if($arguments['related_module']=="Contacts" && $arguments['link']=="contacts" && $arguments['module']=="Opportunities"){
$Oportunidade = BeanFactory::retrieveBean('Opportunities', $arguments['id']);
if($Oportunidade!=null){
$Contato = BeanFactory::getBean('Contacts', $arguments['related_id']);
if($Contato->tipo_contato_c=="Aluno" || $Contato->tipo_contato_c=="Responsavel_aluno"){
if($Oportunidade->nome_aluno_c!=$Contato->name){
$Oportunidade->nome_aluno_c = $Contato->name;
$Oportunidade->save();
}
}
}
}
}
}
}
?>

Error in log:

Wed Sep 21 12:27:33 2016 [886][c74d4e5e-fe90-7727-4284-578fb3919d25][FATAL] Query Failed: INSERT INTO opportunities_cstm (id_c,data_nome_c,produto_c,qtd_tarefa_agendamento_c,nome_aluno_c,encerrar_lembretes_c,qtd_reagendamento_prova_c,segmento_c,qtd_tarefa_provamatricula_c,qtd_tarefa_lembrete_c,qtd_tarefa_doublecheck_c,tipo_cadastro_c,qtd_tarefa_reagendamento_c,unidade_c,qtd_tarefas_c,unidade_segmento_c,estagio_recusa_c,curso_c,data_agenda_concurso_c,contact_id_c)
VALUES ('c19ee0e2-7ff6-11e6-b28d-027a430c0995','21/9/2016 9:27','',0,'Bruno Ribeiro','',0,'3',0,0,0,'Agendamento',0,'16',0,'47','Cadastro','',NULL,'b8304b40-7ff1-11e6-9bd6-027a430c0995'): MySQL error 1062: Duplicate entry 'c19ee0e2-7ff6-11e6-b28d-027a430c0995' for key 'PRIMARY'
Wed Sep 21 12:27:33 2016 [886][c74d4e5e-fe90-7727-4284-578fb3919d25][FATAL] Error inserting into table: opportunities: Query Failed: INSERT INTO opportunities (id,name,date_modified,modified_user_id,created_by,deleted,amount,amount_usdollar,date_closed,date_closed_timestamp,sales_stage,sales_status,probability,best_case,worst_case,commit_stage,total_revenue_line_items,closed_revenue_line_items,included_revenue_line_items,mkto_sync,assigned_user_id,team_id,team_set_id,currency_id,base_rate)
VALUES ('c19ee0e2-7ff6-11e6-b28d-027a430c0995','Bruno Ribeiro - SARTRE ITAIGARA - 21/9/2016 9:27','2016-09-21 12:27:26','c74d4e5e-fe90-7727-4284-578fb3919d25','c74d4e5e-fe90-7727-4284-578fb3919d25',0,0,0,'1970-01-01',0,'Prospecting','In Progress',10,0,0,'exclude',0,0,0,0,'c74d4e5e-fe90-7727-4284-578fb3919d25','88e64e74-772c-51cb-f3cf-5792bbb6d712','c4898596-7ff6-11e6-8cdb-027a430c0995','-99',1): MySQL error 1062: Duplicate entry 'c19ee0e2-7ff6-11e6-b28d-027a430c0995' for key 'PRIMARY'

Outcomes