How to create a logic hook to create Relationship

Hi

I am trying to create a logic hook to insert record in relationship table.

I have created relation between Opportunity and a custom module Opportunity Items.

this is my code:

                       $oppItemsId = '' ;

                       $OpportunityId='';
                        $rel_name = 'opportunities_s_opportunity_items_1';

                        $oItems = new Opportunity();
                      
                        $oItems = retrieve($OpportunityId);                       
                        $oItems->load_relationship($rel_name);
                        $oItems->$rel_name->add($oppItemsId);  
                        $oItems->save();

it will give error "Call undefined function  retrieve() " .

can any one please help me.

Thank you in advance.

  • Hi Ajit Agarw,

       Can you please try   $oItems ->retrieve($OpportunityId);  instead of  $oItems = retrieve($OpportunityId);

    Thanks.

  • You can also try the following:

    $oItems = BeanFactory::getBean('Opportunities', $opportunityId);
    $oItems->load_relationship($rel_name);
    $oItems->$rel_name->add($oppItemsId); 
    $oItems->save();

    Hope it helps,

    David.

  • Hi Bhargavi Patel,

    Thanks You,

    Can you please help how can i check under logic hook that Opportunity is selected or not for lead conversion.

  • Hi Ajit Agarw,
       
       You can use this for check  opportunity is selected or not for lead conversion under logic hook.

       $Olead is bean of Lead. 

       if (!empty($Olead->opportunity_id))
       {
                echo "Opportunity is selected for lead conversion and opportunity id is: ".$Olead->opportunity_id;
       }

    Thanks.