Well,
I am not sure if this is the correct way to do it or not, but I did find a way to make it work.
When I set up the additional modules, I created a one-to-many relationship to Contacts for each Module (eg, each Contact can belong to one Facilitator / each Facilitator can have many Contacts = many Contacts to one Facilitators). This way, the Contact name appears in the Subpanel of the other Module (eg Facilitators) once the relationship is established.
This left me with 4 Relate Fields showing on the Contact Editview and Detailview.
But I only wanted the user to be able to connect each Contact to ONE of Accounts, Facilitators, Venues or Caterers.
So, I hid the 4 relate fields and added one Flex_Relate field with the 4 Modules (Accounts, Facilitators, Venues, Caterers) as the Parent_type options.
I also added a field called Company Type (contact_co_type) so I could later list, sort and search based on Company Type, using descriptors the user would understand.
To prevent the possibility that a user could create one relationship and then go back later and create another, without removing the first, I added a logic hook that triggered the following code
Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class ContactsLogicHook
{
function company_type(&$focus, $event, $arguments)
{
// Populate the Company Type for this Contact based on the selection from the Flex-Relate Field
// If Account Type was already chosen (eg for Converted Lead)
// then set Flex-Relate Field so it will display and link properly
// otherwise set appropriate Company based on Flex_relate selection
// This method is used to ensure that Subpanels in the Company views are populated
// using the one-many relationship established manually
if ( ($focus->parent_type == "") && ($focus->account_name != "") )
{
$focus->parent_type = "Accounts";
$focus->parent_name = $focus->account_name;
$focus->parent_id = $focus->account_id;
$focus->contact_co_type = "Account";
}
elseif ($focus->parent_type == "Accounts")
{
// Set this Contact relationship
$focus->contact_co_type = "Account";
$focus->account_name = $focus->parent_name;
$focus->account_id = $focus->parent_id;
// Undo the other Contact Relationships
// (this is as a precaution in case another was previously set)
$focus->evmgr_fac_contacts_name = "";
$focus->evmgr_fac7b_fac_ida = "";
$focus->evmgr_ven_contacts_name = "";
$focus->evmgr_vc9ba_ven_ida = "";
$focus->evmgr_cat_contacts_name = "";
$focus->evmgr_ce069_cat_ida = "";
}
elseif ($focus->parent_type == "EvMgr_Fac")
{
// Set this Contact relationship
$focus->contact_co_type = "Facilitator";
$focus->evmgr_fac_contacts_name = $focus->parent_name;
$focus->evmgr_fac7b_fac_ida = $focus->parent_id;
// Undo the other Contact Relationships
// (this is as a precaution in case another was previously set)
$focus->account_name = "";
$focus->account_id = "";
$focus->evmgr_ven_contacts_name = "";
$focus->evmgr_vc9ba_ven_ida = "";
$focus->evmgr_cat_contacts_name = "";
$focus->evmgr_ce069_cat_ida = "";
}
elseif ($focus->parent_type == "EvMgr_Ven")
{
// Set this Contact relationship
$focus->contact_co_type = "Venue";
$focus->evmgr_ven_contacts_name = $focus->parent_name;
$focus->evmgr_vc9ba_ven_ida = $focus->parent_id;
// Undo the other Contact Relationships
// (this is as a precaution in case another was previously set)
$focus->account_name = "";
$focus->account_id = "";
$focus->evmgr_fac_contacts_name = "";
$focus->evmgr_fac7b_fac_ida = "";
$focus->evmgr_cat_contacts_name = "";
$focus->evmgr_ce069_cat_ida = "";
}
elseif ($focus->parent_type == "EvMgr_Cat")
{
// Set this Contact relationship
$focus->contact_co_type = "Caterer";
$focus->evmgr_cat_contacts_name = $focus->parent_name;
$focus->evmgr_ce069_cat_ida = $focus->parent_id;
// Undo the other Contact Relationships
// (this is as a precaution in case another was previously set)
$focus->account_name = "";
$focus->account_id = "";
$focus->evmgr_fac_contacts_name = "";
$focus->evmgr_fac7b_fac_ida = "";
$focus->evmgr_ven_contacts_name = "";
$focus->evmgr_vc9ba_ven_ida = "";
}
}
}
?> The convoluted field names )liek evmgr_fac7b_fac_ida) are the system generated (Module Builder) record id fields for the relationship table, which I got by looking in the vardefs file created to establish the relationship.
Note that I also added a check to see if the Account type was already created - like would be the case or a Lead converted to an Account and set the parameters accordingly if that was the case.
It works,
By setting the id field to "", it seems to set the Deleted filed in the relationship to 1. As I said, I am not sure this is how you are supposed to do it, but it works.
If anyone else has a more elegant (read abides by the SugarCRM programming convention rules that I do not know about) way to do this, please let me know.
Bookmarks