Trying to create a relationship between Opportunities and Meetings and use the existing subpanel

The goal is to create a one-to-many relationship of Opportunity to Meetings (opportunity_meetings_1).

As you know, Opportunities already have such a relationship (opportunity_meetings) because Meetings has a native flex-relate field.

I know that creating a new relate field in this case would add an additional Meetings subpanel to Opportunities. That makes reports and other things awkward and a lot less practical

I need to create this Opportunity relationship field in Meetings so that when an opportunity is specified there, it is added to the same Meetings subpanel in the oppportunity record.

My installdefs currently contain this code:

$installdefs = array(
  'id' => 'Opportunity_Meetings_Relationship',
  'vardefs' => array(
      array(
          'from' => '<basepath>/vardefs_meetings.php',
          'to_module' => 'Meetings'
      ),
  ),
  'relationships' => array(
      array(
        'meta_data' => '<basepath>/opportunity_meetings_1MetaData.php'
      ),
  ),
);

Where the vardefs_meetings.phpfile defines a relationship field:

$dictionary['Meeting']['fields']['opportunities'] = array(
    'name' => 'opportunity_meetings_1',
    'type' => 'link',
    'relationship' => 'opportunity_meetings_1',
    'source' => 'non-db',
    'module' => 'Opportunities',
    'bean_name' => 'Opportunity',
    'vname' => 'LBL_OPPORTUNITIES',
    'id_name' => 'opportunity_meetings_1_id',
    'link-type' => 'one',
    'side' => 'left',
);

And I originally added all the fields and indices and everything as per the Developer Guide, but now I'm just using adjusted values that I copied from the native opportunity_meetings relationship with hope that it would use the same relationship table or something and use the same Meetings subpanel in Opportunities rather than creating yet another Meetings subpanel:

$dictionary['opportunity_meetings_1'] = array(
    'name' => 'opportunity_meetings_1',
    'lhs_module' => 'Opportunities',
    'lhs_table' => 'opportunities',
    'lhs_key' => 'id',
    'rhs_module' => 'Meetings',
    'rhs_table' => 'meetings',
    'rhs_key' => 'parent_id',
    'relationship_type' => 'one-to-many',
    'relationship_role_column' => 'parent_type',
    'relationship_role_column_value' => 'Opportunities',
);

But, alas, no subpanel is created at all and I have no Opportunity relationship field that I could place on the layout for Meetings.

  • Hi Artis,

    May I ask why you need another relationship?

    Perhaps there is a better solution to your business requirement than creating another relationship.

    You could certainly create another relationship or add a relate field but for reporting purposes it is more about where the data lives in the database than where the relationship is displayed. If you add a relationship you will have a new table, if you add a new relate field you will have a new field in the Meetings table.

    Keep in mind that subpanels are just a display of the data, and as such could be customized to include data from multiple database sources.

    If you are not familiar with the difference between a relationship, relate field, and flex relate see:

    http://support.sugarcrm.com/Knowledge_Base/Studio_and_Module_Builder/Introduction_to_Relationships_and_Relate_Fields/ 

    I hope this helps,

    FrancescaS

  • Hi Francesca,

    I need it to be possible to have Meetings that are related to a parent record (any module in the native flex-relate field) while also having the option to additionally relate the meeting to an opportunity.

    The most important thing is to have the meetings related to an opportunity this way appear in reports together with meetings that have been related to the opportunity in a different way (by default appearing in the one existing subpanel).

  • Hi Artis,

    You need to distinguish between what you want to see in the subpanel and reporting sources.

    When you save a Meeting as related to the Opportunity using the flex-relate you are populating the parent_type and parent_id in the Meeting record. 

    So, for example, say you add a relate field on the Meeting specifically for Opportunity.

    This will add a field on the Meeting record for the Opportunity ID, let's call it: opportunity_id_c.

    In this scenario a Meeting related to the Opportunity via the flex relate will have:

    parent_type = "Opportunities" and parent_id = "<the opportunity id>"

    While a Meeting related to the Opportunity via your new relate field will have:

    opportunity_id_c = "<the opportunity id>"

    So the source of your data will changed based on HOW the Meeting is linked to the Opportunity.

    You could then see both in a report by using an OR:

    (meetings_cstm.opportunity_id_c = '123-123-123') OR 
    (meetings.parent_type = 'Opportunities' AND meetings.parent_id = '123-123-123')

    You could then try to build a custom subpanel for the Opportunities module that will display both.

    Another option you have, which would make your life easier in the long run) is to remove the Opportunity option from the flex relate parent dropdown and force users to relate Meetings to Opportunities via the custom relate field.

    This way, a Meeting can be related to an Opportunity ONLY via the custom field and never via the flex-relate. Now you have only one source for the link between the Opportunity and the Meeting and that is the opportunity_id_c (based on our example above).

    You can then add a subpanel to display the Meetings on the Opportunity record based on this new relate field, and report via that single link between Opportunity and Meetings.

    I chose to demonstrate the case with a new relate field for simplicity.

    Should you choose to add that custom link between the modules, I suggest that you create a Many-to-One relationship between Meetings and Opportunities instead of adding a relate field.

    The Many-to-One is very similar to the relate field discussed above but will give you the Meetings subpanel on Opportunities by default, instead of you having to create one.

    I hope this helps,

    FrancescaS

  • Hi Francesca,

    Thank you very much for the detailed explanation of these options, that was really helpful! This does seem like more effort than what it accomplishes for the user, so I may only try doing this later.