I want to add a “Referred By” field in Accounts module, and map it with “Referred By” in Leads module.
I tried two scenarios one using vardefs and the webhooks
1- for the vardefs the only type worked is relate but in editview it brings error as the mapped value is not a relate value.
<?php
class MapReferredToHook {
public function mapField($bean, $event, $arguments) {
// Check if the Lead is converted and associated with an Account
if ($bean->converted && !empty($bean->parent_id)) {
// Load the related Account record
$account = BeanFactory::getBean('Accounts', $bean->parent_id);
if ($account) {
// Update the Hook field in the Account
$account->referred_by_c = $bean->refered_by; // Ensure 'refered_by' matches the actual field name
$account->save();
}
}
}
}
If you mean when a lead converts to an account the data gets copied over, all you have to do is ensure the field name and type are the same in both modules. The conversion process takes care of this. It will populate it once on conversion.
If you mean you ALWAYS want to ensure the lead field matches Account field, then you need to write a scheduled job to compare both fields and make them equal as a scheduled job.
The other option is to create a non-db field in the Account and have it populated by function. ie: equal to the related lead field.
As mentioned I’d create a field in Account EXACTLY the same as the one in leads and it will take care of itself. This is the easiest.
OR…
You can do a logic hook for new Accounts to populate the field from the related lead.
You may also be able to do this with workflow.
The other option is to equate the fields in the convertdefs.php. This is how I normally match fields.
By far the easiest is option #1. you might run into the fact that the field is reffereredby (or whatever it is in the lead) and it’s referedby_c in the Account. Vardefs you can edit the _c field and just remove it and re-name it. (you’ll have to re-populate it after, so have a download of all the records.) Search this forum for changing field name. There are a few detailed posts on how to do.
The solution was to manually create the field by:
1- creating the file: /custom/Extension/modules/Accounts/Ext/Vardefs/_override_sugarfield_refered_by.php
2- Then adding the same definition in the “refered_by” file in “Leads” module, and it was as follows:
<?php
// created: 2025-01-05 10:27:14
$dictionary['Account']['fields']['refered_by']['help']='Identifies who refered the lead';
$dictionary['Account']['fields']['refered_by']['comments']='Identifies who refered the lead';
$dictionary['Account']['fields']['refered_by'] = array(
'name' => 'refered_by',
'vname' => 'LBL_REFERED_BY',
'type' => 'varchar',
'len' => '100',
'merge_filter' => 'enabled',
);
?>
3- Updated the language file in: custom/Extension/modules/Accounts/Ext/Language/_override_en_us.lang
to add:
$mod_strings['LBL_REFERED_BY'] = 'Referred By:';
4- Lastly, performed “Quick Repair and Rebuild”, and made sure that its column was created in the database.