SugarCRM Developer Blog

HOWTO: Concatenate two fields into one

03 Feb, 2012
Posted By: John Mertic

Here’s a post from a while back in the forums:

I would like to know how can i concatenate 2 fields (fisrt_name_c and last_name_c) on the field (name) by logic_hook? And the field (name) must be on the edit form or can be append directly on the table???
Can someone teach me the code to accomplish that on the logic_hook.php

Many thanks

As you can read on that thread, there were many different ways to solve the problem with various code changes and logic hooks. However, a really fast an easy way to do this comes along with Sugar Logic, using the very handy concat function as shown below as the calculated value for the field:

concat($first_name_c," ",$last_name_c)

This will make the field instantly update-able on EditViews, and completely in sync throughout the rest of the application.

  • http://twitter.com/matthewpoer Matthew Poer

    For  older installations that don’t have Sugar Logic, we can also used Logic Hooks. Do a before_save hook that looks something like
    newField = “$bean->fieldOne $bean->fieldTwo”;
        }
    }

    The drawback is that this wouldn’t be dynamic on-screen; the concatenation would only happen as you save the record.

  • http://twitter.com/jmertic John Mertic

     Thanks for providing this Matt!

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.