AnsweredAssumed Answered

Using Beans To Get Custom Field Value

Question asked by Jeff C on Feb 1, 2016
Latest reply on Feb 1, 2016 by Hash Softech

I have this code and it works fine.  Although I note there is no field name 'name' in the Contacts module so obviously the bean is combining the two into a filed called name.  This isn't a very good practice though as names can also have middle names and Sugar doesn't have a default field for middle name in Contacts module interestingly.  Not a very smart design.

 

Anyway,  I have this code:

 

$focus = new aCase();

$focus->retrieve($_REQUEST['case_id']);

$focus->load_relationship('contacts');

 

$contact_names = array();

 

foreach ($focus->contacts->getBeans() as $contact) {

    $contact_names[$contact->id]['name'] = $contact->name;

  //$contact_names[$contact->id]['rel'] = $contact->nok_relationship_c;

}

 

I have a custom field in contacts: nok_relationship_c, however if I uncomment that line, it breaks the code.  How to I obtaine the value of a custom field from a bean?

 

Even this didn't work. (I'm running 6.5 Community)

 

$focus = new aCase();

$focus->retrieve($_REQUEST['case_id']);

$focus->load_relationship('contacts');

 

$contact_names = array();

 

foreach ($focus->contacts->getBeans() as $contact) {

    $contact_names[$contact->id]['name'] = $contact->name;

    $QueryRel = $GLOBALS['db'] -> query("

  SELECT 'nok_relationship_c'

            FROM 'contacts_cstm'

            WHERE 'id_c' = '".$contact->id."'

            LIMIT 0,1;");

  $contact_names[$contact->id]['rel'] = $QueryRel;

}

Outcomes