sugarcrmsugarbean

Use SugarCRM Beans to retrieve data


I needed to convert this SQL query to bean format.

"SELECT first_name, last_name FROM leads INNER JOIN  contacts_leads_1_c  ON 
leads.id=contacts_leads_1_c.contacts_leads_1leads_idb  where 
contacts_leads_1_c.contacts_leads_1contacts_ida='".$bean->id."'";

I have this already in place

$lead = new Lead();
$where = "contacts_leads_1_c.contacts_leads_1contacts_ida = '$bean->id' ";
$lead_list = $lead->get_full_list("", $where,true);
$all_leads = array();
foreach($all_leads as $leads){
$bean->contacts_leads = $ref->first_name . ',' . $ref->last_name;

This is the problem

$lead_list = $lead->get_full_list("", $where,true);

Thanks in advance,


Solution

  • If $bean is already a contact you can grab a list of the related fields:

    $leads = $bean->get_linked_beans('FIELDNAME','Leads');
    

    FIELDNAME can be found in the vardefs and isn't the relationship name it's the name of the field that defines the link.

    Note: In your example you're creating an empty array then looping over it.