How to obtain SugarBean from a relate field?

Hi All

I am working in Cases After Save logic hook and need to get a bean from a relate field. I have a relate field named vehicle_c which is related to a custom module called Vehicle. 

When I log the the field below in sugarlog I seem to get the title of the record but I want to access other fields in the record like VIN  (vin_c).

Any ideas on how I can achieve this?

$GLOBALS['log']->fatal(__METHOD__ . " LOG NAME :::: ".$bean->vehicle_c); // This seems to log name of record.
$GLOBALS['log']->fatal(__METHOD__ . " LOG NAME :::: ".$bean->vehicle_c->id); // This logs nothing
  • When using a relate field, there are typically two fields created. One that stores the display name (the logical 'relate' field) and then another that tracks the ID of the related record (the physical 'relate' field).

    If the related module is "vehicle" then you should find a field called "vehicle_id_c" that contains the related ID. You can then create a new SugarBean from that using BeanFactory class. If you are having trouble locating it, check the cached version of your module's vardefs and all the different fields should be listed there.

        'relate_c' => 
        array (
          'labelValue' => 'relate',
          'dependency' => '',
          'required' => false,
          'source' => 'non-db',
          'name' => 'relate_c',
          'vname' => 'LBL_TO_CONFIRM',
          'type' => 'relate',
          ...
          'id_name' => 'lead_id_c',
          ...
        ),

    App Ecosystem @ SugarCRM

  • Hi Matt,

    Thank you for the explanation. Would it be possible to pull the id in the same module with any existing Sugar functionality? 

    Thank you,