I had a scenario where I have the following 3 modules.
Accounts
Contacts
Creditors(My custom Module)
The hierarchy and relationships are as follows
Accounts
|
|-Contacts
|
|-Creditors
Basically there are the relationship of contacts to accounts, and a relationship of creditors to accounts.
I want the creditors to also be related to accounts, in this case the parent account of the contact.
So if I want the creditors module sub panel under contacts to autofill the account field as well.
So it is taking the parent contact field, pulling the contactβs parent, and fillidn that info in to the account field in the Creditors subpanel for Contacts.
basically here.
This is the Creditor subpanel under Contacts module.
When I hit create the crm will auto populate the contact field.
It will not auto populate the account field because I am not creating it there. But I want it to auto populate the account field in which the contact is a child to.
So I found a great tid bit here
we need
Account field name β creditors_accounts_name
Account field id β creditors_accountsaccounts_ida
then we create a custom copy of
include/generic/SugarWidgets/SugarWidgetSubPanelTopButtonQuickCreate.php
to
custom/ include/generic/SugarWidgets/SugarWidgetSubPanelTopButtonQuickCreate.php
then there is a foreach loop looking like this
// fill in additional form fields for all but action
foreach($additionalFormFields as $key => $value)
{
if($key != 'action')
{
$button .= '<input type="hidden" name="' . $key . '" value=\'' . $value . '\' />' . "\n";
}
}
we need to enter the following code right above it like so
//echo $relationship_name to find its name
//echo $relationship_name;
//hack to set the account field to be the same as the parent for the contact
if($relationship_name == 'f_creditors_contacts'){
$additionalFormFields['f_creditors_accounts_name']=$defines['focus']->account_name;
$additionalFormFields['f_creditors_accountsaccounts_ida']=$defines['focus']->account_id;
}
// fill in additional form fields for all but action
foreach($additionalFormFields as $key => $value)
{
if($key != 'action')
{
$button .= '<input type="hidden" name="' . $key . '" value=\'' . $value . '\' />' . "\n";
}
}
return $button;
}
I had trouble because i spelled the relationship wrong, so i threw a few echos to debug and get the field names
And that is it, it pulls the contacts parent account record and fills it in for the user.
This is a huge help as the system will fill up with many accounts and to search for them and inpout the right one wiht the right name would be a waste of time.
I hope this helps others out there as well.