How to create a non-db field linked to a custom field in a related module?

I have two custom fields ( field_one_c, field_two_c ) in Account module. I want to display the field_one and field_two values in the cases modules details view . In the cases module, we have to display these fields value of the particular account which is linked to that case.
These value should not be stored in the cases table. We just have to display the values in the cases Detail view.
I have followed this two ways but it is not meeting the requirements.
  1. I tried calculated fields but its storing the value in the database.
  2. I have tried the non db field but it is not display the  value ( because As per sugarcrm, custom fields from related modules will not be display ( available)  . Check this url : http://developer.sugarcrm.com/2012/03/13/howto-grab-fields-from-a-related-record-without-sugar-logic... )
Any help would be greatly appreciated.


Thanks

Ananth. K
  • I cant get that developer link to work here but that would be how I would do it.  A non-db field that is filled in from a after_retrieve logic hook.

    So I would add a non-db field like

    <?php
    $dictionary['Task']['fields']['customerName'] = array(
    	'name' => 'customerName',
    	'type' => 'varchar',
    	'source' => 'non-db',
    	'len' => '255',
    	'vname' => 'LBL_CUSTOMERNAME',
    );

    and then fill it from an after_retrieve logic hook like this

    <?php
    public function afterRetrieveLogic(SugarBean $bean, $event, $arguments)
    	{
    		$parent_id = $bean->parent_id;
    		$parent_type = $bean->parent_type;
    		if ($parent_type == 'Accounts') {
    			$locationBean = BeanFactory::getBean('Accounts', $parent_id);
    			if (!empty($locationBean->name)) {
    				$bean->locationName = $locationBean->name;
    				$customerName = $locationBean->accounts_accounts_3_name;
    				if (!empty($customerName)) {
    					$bean->customerName = $customerName;
    				}
    			}
    		}
    	}

  • I know the original post is over 6 years old and refers to non-sidecar versions of Sugar but just in case anyone gets here by searching and wants this info:

    As Kenneth says, the "after_retrieve" logic hook is where to fill the data in for a non-db defined field. However, that only fills in the data for display in the record view. To get the field to display in list views (including sub-panels and dashlets) you also need to fill in the data in the "process_record" logic hook.

    The content of your "process_record" logic hook would match the "after_retrieve" here so, to use proper programming standards, you would normally want a separate, private function in your class that collects and returns your field value and call it from both hooks to avoid duplicated code.

    Thanks,

    JH.

  • Yeah, I apparently had my sorting set wring yesterday and I replied to all the oldest posts on the page.  I did not know that the after_retrieve was not run in listviews.  I will have to check that out on my system as we have a lot of nondb fields.