Email Opt-Out

Hi All,

Trying to surface whether the email list displayed in Contacts List view has opted out or not. Over in the Admin studio I can add “email_opt_out” as a column but its return a blank disabled checkbox regardless of opt-out value for the contact, any ideas how I can do this? Feels like a bunch of fields available in detail view aren’t available in list view?

Kind regards
David

What is your version of SuiteCRM?

The opt-in status is displayed as a little check right next to the email address. (see https://docs.suitecrm.com/user/modules/confirmed-opt-in-settings/ )

I’m not sure, but I thought opt-out would also show as a small sign next to the email, doesn’t it? (can’t test right now)

Thanks for getting back to me,

This is the opt-out, not the opt-in ticks - we’re looking to make the opt-out a lot more clearer when its been ticked/enabled to our users and even perhaps obscure email addresses in lists. I’ve been messing about with adapting the contact list via a logic hook but that field seems empty. I’m new to SuiteCRM so probably something I need to understand about how those fields work.

regards
David

Sorry to be clearer, the opt-out merely shows nothing, no icon. I think when opt-in is awaiting some confirmation it’ll show a grey tick. Nothing seems directly related to the opt-out field.

regards

Your initial approach of adding the field to the List View in Studio should have worked… I think.

Are you a developer? If so, I would advise perhaps a solution like this

http://www.jsmackin.co.uk/suitecrm/suitecrm-list-view-conditional-formatting/

to make opted-out emails look different.

Hi,

Funnily enough that’s the exact link i’ve been playing with the last few hours. I’ve even tried returning print_r($bean) to see whats in there but the email_optout field is blank. Is that field representing the primary email1 field’s opt-out tick box?

Curious how the email gets displayed via that bean also, is it a subquery? perhaps that’s why the opt-out isn’t behaving as expected, as related to that field.

Thanks for your help so far
regards
David

looking in the bean, the SugarEmailAddress Object looks like it has some interesting options in there but will need to read up how that’s used…!

regards

ok, so if I run my hook like this:

class EmailOptOutLogicHook {

    public function emailOptOut(SugarBean $bean, $event, $arguments){

    	$sea = new SugarEmailAddress;
    	$addresses = $sea->getAddressesByGUID($bean->id, 'Contacts'); 
    	$count = 0;
		foreach ( $addresses as $a ) {
		    if($a->opt_out == 1)
		    {
		    	$count++;
		    }
		}

		if($count > 0)
		{
			$colour = substr(md5($bean->name),0,6);
        		$bean->EMAILFIELD??? = '<div style="border: solid 5px #red;">'.$primary_address.'<div>';
		}
    }

}

If can then loop through all addresses for that Contact bean, decided whether to act on any email being opted out, or only if primary, a few options. I’m unsure if this is incredibly inefficient as a subquery once loading a large table of contacts or is normal practice in SuiteCRM. My last issue is I still can’t see where the email address link is being constructed, I can’t inject anything from that hook into that column in the list? Presumably this happens else where perhaps a different hook.

Any help appreciated!
regards
David

If you’re not using XDEBUG and an IDE, here’s a trick to help you find fields


$myfield_defs = $SomeBean->getFieldDefinitions(); 
foreach($myfield_defs as $def) echo $def["name"] . "<br />\n";

That’s the thing though - I can find the fields but in the Contact bean in list view email is blank, as is opt-out. In the metadata the email is defined as:

'EMAIL1' => 
  array (
    'width' => '15%',
    'label' => 'LBL_LIST_EMAIL_ADDRESS',
    'sortable' => false,
    'link' => true,
    'customCode' => '{$EMAIL1_LINK}',
    'default' => true,
  ),

Presumably this returns the email address formatted with A tags and opt-in ticks etc. Feels like that isn’t returned in the bean itself but more like a subquery or method either before or after where I’m trying to write the hook.I guess that’s where I want to be changing behaviour but can’t work out where ‘customCode’ => ‘{$EMAIL1_LINK}’ actually goes to process.

regards
David

I don’t know, I’m not that familiar with SuiteCRM code customization myself…

I know that you can have fields marked in the vardefs like this

'source' => 'non-db', 

which are “calculated fields” that you use in the view, but don’t exist in the database. So you could use a new non-db field to show whatever you want (with your formatting, and the email address you got from the loop). Then you would leave the real email field hidden.

thanks, you’ve been a great help, appreciated.

I’ve found this link and this gets me really close:
https://stackoverflow.com/questions/15278977/sugarcrm-smarty-code-in-listviewdefs

I’d still like to work out how to gracefully fall back to that EMAIL_LINK in the metadata though. I shall keep digging. Learned a lot already last 24 hours!