Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Customize fields displaying a value from more than one other field

  1. #1
    meitar is offline Junior Member
    Join Date
    Aug 2010
    Posts
    1

    Default Customize fields displaying a value from more than one other field

    Hi everyone, SugarCRM noob here (so please be gentle). I'm trying to grok Sugar's custom fields paradigm. Here's a simple example:

    In SugarCRM 6.0, a Contact's name is display in a single field (called "Name" in the Studio's "DetailView" layout editor screen). In reality, this name seems to be a concatenation of "First Name" and "Last Name." In America, many people have a "Middle Name" as well. So I went ahead and added a "Middle Name" custom TextArea field created by cloning the "First Name" field.

    Now I'd like the aggregate "Name" field in the Contact Detail layout to include the "Middle Name" field in between the First Name and Last Name if that field is non-empty.

    How can this be accomplished? Can it be done solely using the SugarCRM studio or is there a code change that needs to happen. (I am not afraid of touching PHP code, as long as I can touch it in an upgrade-safe way.)

    My current technology stack:

    • SugarCRM 6.0 Community Edition
    • PHP 5.2.14
    • Apache 2.x


    Thanks in advance for any advice you can offer.

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Customize fields displaying a value from more than one other field

    You need to create a logic_hook after_retrieve on Contacts module in order to concatenate the fields accordingly.


    the logic_hook function may looks like that:

    PHP Code:
    function setFullName(&$focus$event$arguments) {
      
    $name $focus->salutation ' ' $focus->first_name ' ' $focus->middle_name_c ' ' $focus->last_name;
      
    $focus->name $name;
      
    $focus->full_name $name;

    Obviously you need to create the logic_hook class and logic_hook file accordingly.

    Kind regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    erop is offline Sugar Community Member
    Join Date
    Jan 2005
    Location
    Moscow, Russia
    Posts
    107

    Default Re: Customize fields displaying a value from more than one other field

    It might be better to post this message in one of the other topics related to concatenated fields. But my main goal is probably related to mentioned here “logic_hook” technique which I also use in other custom modules. And I would like to decide what to choose in the situation.

    So, I need extended Accounts 'name' field into 'full_account_name' that consists of fields 'billing_address_city', custom dropdown 'account_type_drnt_c' and existing 'name' (the last is now in active use by users). The main goal is to have “one-field” identifier for Account that could clearly define it in relating modules' DetailView, pop-us and so on.

    Thus I created custom/Extension/modules/Accounts/Ext/Vardefs/full_account_name.php:

    PHP Code:
    <?php
    $dictionary
    ['Account']['fields']['full_account_name'] = array(
        
    'name' => 'full_account_name',
        
    'rname' => 'full_account_name',
        
    'vname' => 'LBL_FULL_ACCOUNT_NAME',
        
    'type' => 'name',
        
    'fields' => array(=> 'billing_address_city'=> 'account_type_drnt_c'=> 'name',),
        
    'sort_on' => 'billing_address_city',
        
    'source' => 'non-db',
        
    'group' => 'billing_address_city',
        
    'len' => '255',
        
    'dbType' => 'varchar',
        
    'db_concat_fields' => array(=> 'billing_address_city'=> 'account_type_drnt_c'=> 'name',),
        
    'importable' => 'false',
    );
    ?>
    Then, of course, custom/Extension/modules/Accounts/Ext/Language/en_us.FullAccountName.php :
    PHP Code:
    <?php
    $mod_strings
    ['LBL_FULL_ACCOUNT_NAME'] = 'Full Account Name';
    ?>
    Admin->Repair->Rebuild Extensions.

    In Studio I placed new field in DetailView and then expected its value displayed. But the field was empty in every record. I check custom/modules/Accounts/Ext/Vardefs/vardefs.ext.php – there was the field definition there.
    File custom/modules/Accounts/metadata/detailviewdefs.php also has field definition in proper place:

    PHP Code:
    array (
                
    'name' => 'full_account_name',
                
    'label' => 'LBL_FULL_ACCOUNT_NAME',
             ), 
    But 'full_account_name' field is still empty. Moreover when I placed the field in ListView it shows zero records. Removing new field from ListView gives normal view for all the records.
    I dug Contacts module for similar code trying to find out what I missed. But found no differences between my code and standard Contacts 'full_name' approach. So I really appreciate if someone point me on my mistake.

    The second question is about which of the techniques (logic hook or vardefs-concatenated fields) is more “Sugar-friendly” in the context of future possible bean manipulations. Which method is better to use in terms of future use cases in different situations?

    Thank you!

    P.S. I'm on Sugar CE 5.5.1
    Last edited by erop; 2010-09-23 at 09:08 PM. Reason: Missed some info about Sugar version

  4. #4
    sourjya is offline Member
    Join Date
    Jul 2010
    Location
    Bangkok
    Posts
    18

    Question Re: Customize fields displaying a value from more than one other field

    Quote Originally Posted by andopes View Post
    You need to create a logic_hook after_retrieve on Contacts module in order to concatenate the fields accordingly.


    the logic_hook function may looks like that:

    PHP Code:
    function setFullName(&$focus$event$arguments) {
      
    $name $focus->salutation ' ' $focus->first_name ' ' $focus->middle_name_c ' ' $focus->last_name;
      
    $focus->name $name;
      
    $focus->full_name $name;

    Obviously you need to create the logic_hook class and logic_hook file accordingly.

    Kind regards
    Hello andopes,
    I've implemented your code, but the results aren't showing up in the DetailView.

    Here's my logic hook:
    PHP Code:
    $hook_array['after_retrieve'] = Array(); 
    $hook_array['after_retrieve'][] = array(
            
    100
            
    'set_full_name'
            
    'custom/modules/Leads/leads_custom_logic.php'
            
    'LeadsCustomLogic'
            
    'setFullName'
    ); 
    And here's my function:
    PHP Code:
        function setFullName( &$focus$event$arguments ) {
            
    $name $focus->salutation ' ' 
                    
    $focus->first_name ' ' .
                    ( 
    $focus->middle_name_c ? ( $focus->middle_name_c ' ' ) : '' ) . 
                    
    $focus->last_name;
            
    //echo $name;
            
    $focus->name $name;
            
    $focus->full_name $name;
            echo 
    $focus->full_name;
        } 
    The echo statement is showing the Full Name including the Middle Name. However, the Name display in the DetailView still keeps showing a concatenated result of Salutation + First Name + Last Name ONLY!

    Do I need to modify anything else, elsewhere?

    Thanks,
    Sourjya

    P.S. I also tried the process_record hook - but same results.
    Last edited by sourjya; 2010-11-10 at 06:37 AM. Reason: Added info.

  5. #5
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Customize fields displaying a value from more than one other field

    Hello,

    Try following code in view.detail.php inside display function

    PHP Code:
     $name $this->bean->salutation ' ' 
                    
    $this->bean->first_name ' ' .
                    ( 
    $this->bean->middle_name_c ? ( $this->bean->middle_name_c ' ' ) : '' ) . 
                    
    $this->bean->last_name;
            
    $this->bean->full_name $name
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  6. #6
    sourjya is offline Member
    Join Date
    Jul 2010
    Location
    Bangkok
    Posts
    18

    Default Re: Customize fields displaying a value from more than one other field

    Quote Originally Posted by davidboris View Post
    Hello,

    Try following code in view.detail.php inside display function

    PHP Code:
     $name $this->bean->salutation ' ' 
                    
    $this->bean->first_name ' ' .
                    ( 
    $this->bean->middle_name_c ? ( $this->bean->middle_name_c ' ' ) : '' ) . 
                    
    $this->bean->last_name;
            
    $this->bean->full_name $name
    Davidboris: Thanks for your reply. However, I'm unable to find this file in any folder under custom/modules/Leads. Do I have to copy it over from anywhere else or do I have to mod the Sugar code itself... in which case it won't be upgrade safe. Is there an upgrade-safe way of doing this?

    Thanks,
    Sourjya

  7. #7
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Customize fields displaying a value from more than one other field

    Hello,

    If the file doesn't exist in custom/modules/<MODULE_NAME>/views folder check in modules/<MODULE_NAME>/views and copy and paste the file into custom folder, which makes the change upgrade safe.

    If you dont have the file in main modules, you can refer modules/Contacts/views/view.detail.php and follow the code for your module.
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  8. #8
    sourjya is offline Member
    Join Date
    Jul 2010
    Location
    Bangkok
    Posts
    18

    Angry Re: Customize fields displaying a value from more than one other field

    Tried your option and copied the view.detail.php from modules/Contacts/views to custom/modules/Leads/views and modified to the following code:
    PHP Code:
    class LeadsViewDetail extends ViewDetail 
    {
         
    /**
          * @see SugarView::display()
         *
          * We are overridding the display method to manipulate the portal information.
          * If portal is not enabled then don't show the portal fields.
          */
         
    public function display() 
         {
            
    $admin = new Administration();
            
    $admin->retrieveSettings();
            if(isset(
    $admin->settings['portal_on']) && $admin->settings['portal_on']) {
               
    $this->ss->assign("PORTAL_ENABLED"true);
            }
            
    $name $this->bean->salutation ' ' 
                    
    $this->bean->first_name ' ' .
                    ( 
    $this->bean->middle_name_c ? ( $this->bean->middle_name_c ' ' ) : '' ) . 
                    
    $this->bean->last_name;
            
    $this->bean->full_name $name;  
            
    $this->bean->name $name;
             
    parent::display();
         }

    But still the full name won't show up. If I insert the following statement in my LH function (setFullName):
    PHP Code:
    echo $bean->id' '$bean->name'<br />'
    Here's the output I get:


    As you can see, once the record has been pulled up and after_retrieve fires, the above statement shows the ID and Full Name (along with Middle Name) just fine.

    But the breadcrumbs as well as the Name field in the DetailView still don't reflect the change!!

    There's no reason NOT TO!

  9. #9
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Customize fields displaying a value from more than one other field

    Hello,

    I used exactly your code and for me it worked for field, though it will not work for breadcrumbs.
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  10. #10
    sourjya is offline Member
    Join Date
    Jul 2010
    Location
    Bangkok
    Posts
    18

    Default Re: Customize fields displaying a value from more than one other field

    Hi David,
    Which version of Sugar are you using? Mine's OS 6.0.0. I'm wondering if it's a version specific problem !!

    Cheers,
    Sourjya

    UPDATE
    It's working for me now in the Field block... but like you said, the Breadcrumbs still won't. Any ideas where the breadcrumb template lies?

    Thanks for ALL THE HELP
    Last edited by sourjya; 2010-11-12 at 02:22 AM. Reason: Updated info.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 2010-02-06, 08:21 AM
  2. How to customize field in crm(Make field mandatory)
    By sadique in forum Sugar Developer Website
    Replies: 8
    Last Post: 2009-09-03, 02:53 PM
  3. Custom Fields not displaying Information
    By jeffreyvsmith in forum Help
    Replies: 0
    Last Post: 2009-06-05, 04:20 PM
  4. Displaying Relate fields in Subpanels in 5.1
    By NateL in forum Developer Help
    Replies: 1
    Last Post: 2008-09-26, 02:40 AM
  5. Replies: 17
    Last Post: 2006-09-22, 05:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •