Skip to content

Instantly share code, notes, and snippets.

@dmulvi
Last active February 9, 2017 22:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmulvi/37580d51f58efe7c8e6f to your computer and use it in GitHub Desktop.
Save dmulvi/37580d51f58efe7c8e6f to your computer and use it in GitHub Desktop.
SugarCRM 7 - add fields to Full Name headerpane display (middle name, nick name, preferred name etc)
/*
* I only wanted to apply this change to the Contacts modules so I put this file in:
* custom/modules/Contacts/clients/base/fields/fullname/
*/
({
extendsFrom: 'FullnameField',
formatMap: {
'f': 'first_name',
'l': 'last_name',
's': 'salutation',
'p': 'preferred_name_c',
'm': 'middle_name_c'
},
initialize: function(options) {
// override the name format for this module
app.user.setPreference('default_locale_name_format', 's f p m l');
this._super('initialize', [options]);
},
format: function() {
var fullname = this.model.attributes.salutation +' '+ this.model.attributes.first_name +' ';
fullname += (!_.isEmpty(this.model.attributes.preferred_name_c)) ? '"'+ this.model.attributes.preferred_name_c +'" ': ' ';
fullname += this.model.attributes.middle_name_c +' '+ this.model.attributes.last_name;
return fullname;
},
})
<?php
/*
* This is the custom record file for Contacts.
* custom/modules/Contacts/clients/base/views/record/record.php
*/
<?php
$viewdefs['Contacts'] =
array (
'base' =>
array (
'view' =>
array (
'record' =>
array (
'buttons' =>
array (
// ....
),
'panels' =>
array (
0 =>
array (
'name' => 'panel_header',
'header' => true,
'fields' =>
array (
0 =>
array (
'name' => 'picture',
'type' => 'avatar',
'size' => 'large',
'dismiss_label' => true,
),
// THIS IS THE IMPORTANT PART
1 =>
array (
'name' => 'full_name',
'label' => 'LBL_NAME',
'dismiss_label' => true,
'type' => 'fullname',
'fields' =>
array (
0 => 'salutation',
1 => 'first_name',
2 => 'preferred_name_c',
3 => 'middle_name_c',
4 => 'last_name',
),
),
<?php
/*
if you're trying to display the fullname in the subpanel for your updated module and middle_name or
another field displays as undefined try the following:
open the file:
/modules/Contacts/clients/base/views/subpanel-list/subpanel-list.php
copy the contents of that file to:
/custom/modules/Contacts/clients/base/views/subpanel-list/
edit the fields['full_name'] section as below
*/
$viewdefs['Contacts']['base']['view']['subpanel-list'] = array(
'type' => 'subpanel-list',
'panels' =>
array(
array(
'name' => 'panel_header',
'label' => 'LBL_PANEL_1',
'fields' => array(
array(
'name' => 'full_name',
'type' => 'fullname',
'fields' => array(
'salutation',
'first_name',
'last_name',
),
'link' => true,
'label' => 'LBL_LIST_NAME',
'enabled' => true,
'default' => true,
// ADD THIS PART
'related_fields' => array(
'middle_name_c'
),
// END OF ADDITION
),
// the rest of the fields have been removed for brevity, you keep them obviously
)
)
)
);
@noimang
Copy link

noimang commented Feb 1, 2017

After I created and save It is undefimed of middle name

@dmulvi
Copy link
Author

dmulvi commented Feb 5, 2017

Hey noimang, Do you have a field for the middle name added to the module? For example, in the code above we have a custom field named middle_name_c. Does that field exist in the module that you are customizing? Also, if it does exist try adding the field directly to the layout to see if it has a value. You can try to add it to both record and list layout to see if it shows up. The last thing to consider is that you may need to add the middle_name_c field to the available fields list in the listview of studio (the middle column). Good luck and I hope this helps!

@dmulvi
Copy link
Author

dmulvi commented Feb 9, 2017

Below is an example image of how to add the middle_name_c field to the available column in studio for the module. You can find the below configuration in admin > Studio > MODULE_NAME > layouts > list

middle-name-available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment