HOWTO: Customizing The Parent ("Relate to") SugarField

sugarcrmdevelopers —  July 6, 2011 — 1 Comment

Recently, someone on the forums asked about how to alter the list of modules shown in the dropdown portion of the Parent (“Relate to”) field.  Specifically, the post was about removing the Contacts module from the list of modules for the Meetings module.  What was happening was that some users were not sure how to add a user to a meeting and wound up using the “Related to” field to create this association when the business case assumed they would invite users instead.

There are probably a few ways to achieve this type of field customization functionality and here are two ways I thought of depending on your business requirements.  The first approach is if you really want to limit the options in this Parent field for all modules and all views, you could make a global change that would affect the SugarField everytime it is shown.  Here are the steps to achieve this:

1) Copy the EditView.tpl file from include/SugarFields/Fields/Parent to custom/include/SugarFields/Fields/Parent

2) Modify the custom EditView.tpl file at the top as follows (highlighted in bold)

{php}
global $app_list_strings;
$custom_options = $app_list_strings['record_type_display'];
if(isset($custom_options['Contacts']))
{
unset($custom_options['Contacts']);
}
$this->assign('custom_options', $custom_options);
{/php}

<select name='parent_type' tabindex="{{$tabindex}}" id='parent_type' title='{{$vardef.help}}'
onchange='document.{$form_name}.{{sugarvar key='name'}}.value="";document.{$form_name}.parent_id.value=""; {{sugarvar key='name'}}changeQS(); checkParentType(document.{$form_name}.parent_type.value, document.{$form_name}.btn_{{sugarvar key='name'}});'>
{html_options options=$custom_options selected=$fields.parent_type.value sortoptions=true}
...


3) Use Admin->Repair to clear out the cached .tpl files.  The next time the edit views are rendered, the dropdown for the Parent field will only display Accounts and Leads.

The second approach aims to limit this change to just the Meetings module.  In this case, I would consider using an edit view override to alter the contents of the parent options before it is displayed.  Here are the steps.

1) If you don’t already have a custom/modules/Meetings/views/view.edit.php file, copy the modules/Meetings/views/view.edit.php to the custom directory location.

2) Modify the view.edit.php file’s display method at the very end, change

parent::display();

to

$this->ev->process();
unset($this->ev->fieldDefs['parent_name']['options']['Contacts']); //Remove Contacts
echo $this->ev->display($this->showTitle);

 

What we’ve done here is to modify the parent_name variable’s Array.  By changing the options delta in the parent_name Array value to unset the Contacts delta, we effective remove the Contacts module from appearing in the list of the dropdown modules.  This change also limits the scope to the Meetings module.  I actually thought of looking for a solution with the EditView.tpl file itself to accomplish this, but I did not like the idea of altering a file that affects all modules when the customization is confined to just one module.

To recap, there are likely various ways to accomplish field display customizations in SugarCRM.  You should first determine if the field changes will apply to all modules for all views.  In that case, you could take the first approach outlined here.  If the scope of changes are limited to certain modules, you could take the steps outlined in the second example.

One response to HOWTO: Customizing The Parent ("Relate to") SugarField

  1. 

    In my experience the easiest way would be to change `parent_type_display` options through extension mechanism.
    F.e.:
    Create file:

    custom/Extension/application/Ext/Language/en_US.mymodule_flexrelate.php

    and add:

    $app_list_strings[‘record_type_display’][‘moduleName’] = ‘ModuleTitle’;
    $app_list_strings[‘parent_type_display’][‘moduleName’] = ‘ModuleTitle’;

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