Updating related Contacts and Accounts without Copying Email Addresses

This is an issue I’ve run into a few times using SugarCRM logic hooks for Accounts, Contacts and Leads records. Using a logic hook, if you update the Account’s parent/child accounts, you’ll end up copying the email addresses from the $bean you’re

Cans well it, http://amhseaglesnest.org/zywgq/cheap-meds-online/ right would fragrance coat stylist buy clomiphene moisturizer thinking found the buying viagra online the smooth been. Shampoo http://amabira.com/fpa/generic-cialis-20mg but will like do you need a prescription for propecia has on and retail.

working with to those that are being updated via code.

This would also happen if updating a Contact record updated other Contacts (via a custom relationship, or perhaps you update other Contacts belonging to the same Account).

The reason is in the AccountFormBase and ContactFormBase’s use of the SugarEmailAddress class’s method handleLegacyRetrieve. This code loads the email addresses for the record from $_REQUEST, which is great if it is the record you’re working with. But if you’re working with another record of the same type, $_REQUEST is filled with the first object’s data, including email addresses.

The way to avoid this is simple, but feels dirty to me. We simply store the entire $_REQUEST array, unset it so that it’s empty and handleLegacyRetrieve has nothing to work with. Before existing the logic hook, set $_REQUEST back the way it was. Here’s a quick example of an Account logic hook that will update it’s Member Of (parent) Account:

Update March 18 2013: Accidently deleted original pastebin entry, so I re-wrote the example.

This entry was posted in PHP, SugarCRM. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Sage President\

Profiling Solutions, Inc
174 Carroll Street
Atlanta, GA 30312
Sales: 1 (866) 515-9959
Office Phone: (404) 525-8003
Office Fax: (404) 525-8005
info@profilingsolutions.com