How to Change the Account Name field back to a relate field in Leads

In sugarCRM CE the relationship between Leads and Accounts has been changed so that in the Leads editview, the account name does not show as a standard relate field. If for whatever reason you would like to change this back to a standard relate field do the following:

Add the following file in custom/Extension/modules/Leads/Ext/Vardefs/vardefs_change.php

vardefs_change.php:

$dictionary['Lead']['fields']['account_id']['name'] = 'account_id';
//$dictionary['Lead']['fields']['account_id']['rname'] = 'id';
//$dictionary['Lead']['fields']['account_id']['id_name'] = 'account_id';
//$dictionary['Lead']['fields']['account_id']['group'] = 'account_name';
$dictionary['Lead']['fields']['account_id']['vname'] = 'LBL_ACCOUNT_ID';
$dictionary['Lead']['fields']['account_id']['type'] = 'id';
//$dictionary['Lead']['fields']['account_id']['table'] = 'accounts';
//$dictionary['Lead']['fields']['account_id']['isnull'] = 'true';
//$dictionary['Lead']['fields']['account_id']['module'] = 'Accounts';
//$dictionary['Lead']['fields']['account_id']['dbType'] = 'id';
$dictionary['Lead']['fields']['account_id']['reportable'] = false;
//$dictionary['Lead']['fields']['account_id']['source'] = 'non-db';
//$dictionary['Lead']['fields']['account_id']['massupdate'] = false;
//$dictionary['Lead']['fields']['account_id']['duplicate_merge'] = 'disabled';
//$dictionary['Lead']['fields']['account_id']['hideacl'] = true;

$dictionary['Lead']['fields']['account_name']['name'] = 'account_name';
$dictionary['Lead']['fields']['account_name']['rname'] = 'name';
$dictionary['Lead']['fields']['account_name']['id_name'] = 'account_id';
//$dictionary['Lead']['fields']['account_name']['id_name'] = 'id';
$dictionary['Lead']['fields']['account_name']['vname'] = 'LBL_ACCOUNT_NAME';
$dictionary['Lead']['fields']['account_name']['join_name'] = 'accounts';
//$dictionary['Lead']['fields']['account_name']['group'] = 'account_name';
$dictionary['Lead']['fields']['account_name']['type'] = 'relate';
$dictionary['Lead']['fields']['account_name']['link'] = 'accounts';
$dictionary['Lead']['fields']['account_name']['table'] = 'accounts';
//$dictionary['Lead']['fields']['account_name']['isnull'] = 'true';
$dictionary['Lead']['fields']['account_name']['module'] = 'Accounts';
//$dictionary['Lead']['fields']['account_name']['dbType'] = 'varchar';
$dictionary['Lead']['fields']['account_name']['len'] = '255';
$dictionary['Lead']['fields']['account_name']['source'] = 'non-db';
//$dictionary['Lead']['fields']['account_name']['unified_search'] = true;
$dictionary['Lead']['fields']['account_name']['reportable'] = false;
$dictionary['Lead']['fields']['account_name']['save'] = false

Then in custom/modules/Leads/metadata/editviewdefs.php

Change the account_name definition as follows:

array (
0 =>
array (
'name' => 'account_name',
'type' => 'relate',
// 'validateDependency' => false,
//'customCode' =&gt; '<input id="EditView_account_name" type="text" disabled="disabled" maxlength="255" name="account_name" size="30" value="{$fields.account_name.value}" />',
),
1 => 'phone_fax',
),

And in the form hidden fields array comment out the account_id field as this field will interfere with the Javascript call back that populates the id for relate field.

form' => 
      array (
        'hidden' => 
        array (
          0 => '<input type="hidden" name="prospect_id" value="{if isset($smarty.request.prospect_id)}{$smarty.request.prospect_id}{else}{$bean->prospect_id}{/if}">',
          //1 => '<input type="hidden" name="account_id" value="{if isset($smarty.request.account_id)}{$smarty.request.account_id}{else}{$bean->account_id}{/if}">',
          1 => '<input type="hidden" name="contact_id" value="{if isset($smarty.request.contact_id)}{$smarty.request.contact_id}{else}{$bean->contact_id}{/if}">',
          2 => '<input type="hidden" name="opportunity_id" value="{if isset($smarty.request.opportunity_id)}{$smarty.request.opportunity_id}{else}{$bean->opportunity_id}{/if}">',
        ),

Now go to admin then repair and do a quick repair and rebuild and that should be it.

Andy
About

Software Developer from Falkirk, Central Scotland.

Posted in SugarCRM development and customisation
One comment on “How to Change the Account Name field back to a relate field in Leads
  1. Rainolf says:

    Thank you,
    however if i would also populate fileds ex: street address or city based on relate account selection? Just like contact form?

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>