AnsweredAssumed Answered

Insert record in relatioship table with installable package

Question asked by Manuel Rubio on Sep 3, 2016
Latest reply on Sep 4, 2016 by Mehul Bhandari

Hi.

 

Iwnat to create a new record in the "opportunities_contacts" relationship table using an installable package. I've tried with this code but it doesn't work...

 

 

manifest.php

 

<?php

    $manifest =array(
        'acceptable_sugar_flavors' => array('CE','PRO','CORP','ENT','ULT'),
        'acceptable_sugar_versions' => array(
            'exact_matches' => array(),
            'regex_matches' => array('7\\.[0-9]\\.[0-9]\\.[0-9]$'),
        ),
        'author' => 'Imagine CX',
        'description' => 'Logic Hook que asocia un contacto a una oportunidad de Coaching Hall International',
        'icon' => '',
        'is_uninstallable' => true,
        'name' => 'Logic Hook Contacto-Oportunidad',
        'published_date' => '2016-09-01 21:35:00',
        'type' => 'module',
        'version' => '1.0',
    );
    
    $installdefs =array(
        'id' => 'package_1340221359',
        'copy' => array(
            0 => array(
                'from' => '<basepath>/Files/custom/modules/Opportunities/asociacion.php',
                'to' => 'custom/modules/Opportunities/asociacion.php',
            ),
        ),
        'logic_hooks' => array(
            array(
                'module' => 'Opportunities',
                'hook' => 'after_login',
                'order' => 1,
                'description' => 'Asociación de un cntacto a una oportunidad de CHI',
                'file' => 'custom/modules/Opportunities/asociacion.php',
                'class' => 'AsociacionCO',
                'function' => 'cont_opportun_asoc',
            ),
        ),
    );

?>

 

 

 

 

asociacion.php

 

<?php

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

    class AsociacionCO
    {
        function cont_opportun_asoc($bean, $event, $arguments)
        {
            $opp = '6b210975-fc1a-90e1-49aa-523cc7306522';
            $ctc = 'c573fa75-6732-ecc2-3de6-523cc7d95faa';
            
            $sql = "INSERT INTO opportunities_contacts (contact_id, opportunity_id) VALUES ($ctc, $opp)";
            
            $result = $GLOBALS['db']->query($sql);
        }
    }

?>

 

What am I doing wrong?

Outcomes