Output email1 value SuiteCRM 7?

I have a client with many fields, sections and tabs in the contact record.

In one particular section the client wants to display a bunch of fields that are pertinent to that tab. So I’m just outputting the values, which seems to be working like:

0 => 
          array (
            'name' => 'middle_name_c_readonly',
            'label' => 'LBL_MIDDLE_NAME',
            'studio' => 'visible',
            'inline_edit' => false,
            'customCode' => '<input type="text" value="{$fields.middle_name_c.value}" disabled style="width:100%;" />',
          ),

However, this strategy does not seem to be working with email1.

I get it’s an array of many emails possibly, I’d like to grab the first one and/or the primary one. Can this be achieved without writing function to populate the custom code (I’m sure I can do that, but if there is s simpler way to get it I’d like to do that)

THis does not work (at least for editview)

 0 => 
          array (
            'name' => 'email1_readonly',
            'label' => 'LBL_EMAIL_ADDRESS',
            'studio' => 'visible',
            'inline_edit' => false,
			'customCode' => '
  {if $fields.email1.value}
    <span class="sugar_field" style="display:inline-block; padding:5px 8px; border:1px solid #ccc; background:#f5f5f5; border-radius:3px; min-height:28px; line-height:18px;">
      {$fields.email1.value|escape:"html"}
    </span>
  {/if}
',

          ),

I think this will not work with edit view. You have to use the logic hook to retrieve the email address.


Sample Code:

custom/modules/Contacts/logic_hooks.php

$hook_array['before_view'][] = array(
    1,
    'Populate primary_email_c',
    'custom/modules/Contacts/PrimaryEmailHook.php',
    'PrimaryEmailHook',
    'populatePrimaryEmail',
);

PrimaryEmailHook.php

class PrimaryEmailHook {
    function populatePrimaryEmail($bean, $event, $arguments) {
        if (!empty($bean->emailAddress)) {
            $emails = $bean->emailAddress->getAddressesByGUID($bean->id, $bean->module_dir);
            foreach ($emails as $email) {
                if (!empty($email['primary_address'])) {
                    $bean->primary_email_c = $email['email_address'];
                    break;
                }
            }
        }
    }
}

@rsp yes I know I can do that, just wondering if the email1 is available directly to the Smarty Template?

@pstevens I don’t know but I found this in your blog. Check out example 4 :sweat_smile:


https://stackoverflow.com/questions/38893305/suitecrm-custom-template-for-custom-module

If I recall correctly, email1 is not an array with several emails, it is a single email (the first one or the main one, I’m not sure how it picks).

So my first expectation would be that you could just use the field and get an email address, as long as one is defined.

But it is a special field, with special cases for handling it in the code, so I guess that if you don’t get it filled in at that point, you would need to dive into the code building the screen to see what’s happening - which might not be easy.

A couple of tips to search the code:

  • populateLegacyfields in SugarEmailAddress.php

  • getEmailLink function

Thanks @rsp that doesn’t work for what I’m trying to do here.