HOWTO: Concatenate two fields into one

sugarcrmdevelopers —  February 3, 2012 — 2 Comments

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.

2 responses to HOWTO: Concatenate two fields into one

  1. 

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s