Relationship between custom module and Contacts module not working

I have module Feedback and need to create relationship between Feedback and Contacts to get email address from Contact to send Email.

So, I go to Studio to create relationship from Feedback and create relationship btw both but it still not working

I tried another way, I go to module builder and add relationship, it still not working

When I need to send out email from Feedback, it look like cannot get Contact info from Feedback although I like Contact to this record.

function in custom/modules/Emails/clients/base/views/compose/compose.js clone from _populateForCases

_populateForFeedback: function(relatedModel) {
        var config = app.metadata.getConfig(),
            keyMacro = '%1',
            caseMacro = config.inboundEmailCaseSubjectMacro,
            subject = caseMacro + ' ' + relatedModel.get('name');

        subject = subject.replace(keyMacro, relatedModel.get('feedback_number'));
        this.model.set('subject', subject);
        if (!this.isFieldPopulated('to_addresses')) {
            // no addresses, attempt to populate from contacts relationship
            var contacts = relatedModel.getRelatedCollection('contacts');

                relate: true,
                success: _.bind(function(data) {
                    var toAddresses =, function(model) {
                        return {bean: model};
                    }, this);

                    this.model.set('to_addresses', toAddresses);
                }, this),
                fields: ['id', 'full_name', 'email']

Can you suggest a thing that I need to do?




  • Thanks for you help.  

    Its may be another solution for me.

  • Updated things that I had done:

    I tired to add manually via logic hook and it work.

    Create relationship btw custom module and contacts

    I get account id then get contact related to account then add a relation btw custom module and contacts and work.

    function createRelationsWithContacts($bean,$event, $arguments) {
                         // Add contact to custom module
                             $account = new Account();
                             $contacts = $account->get_linked_beans('contacts','Contact');
                             // Relationship name
                                            $rel_name = 'custom_module_contacts_1';
                             foreach ($contacts as $contact){
                                       $c = new Contact();


  • don't use get_linked_beans, I'm pretty sure it doesn't work anymore, or at the very least it's deprecated. (I assume you are on 7.x) you need to fetch the relationship by link:… 

    It will look something like this (look in Studio at the name of the relationship, that's the $link name:

          $link = 'contacts';
            foreach($bean->$rel->getBeans() as $contact){

    also, don't use the Class to create a bean but the BeanFactory:… 

    so instead of 

    $account = new Account();


    $account = BeanFactory::retrieveBean('Accounts', $bean->account_id);

    similarly for your Contact bean.



  • Hi Autchara Chaiprom.

    Can you try with this?

    In your JavaScript code, instead of:

    var contacts = relatedModel.getRelatedCollection('contacts');

    try with:

    var contacts = relatedModel.getRelatedCollection('feedback_contacts_1');

    I guess this can be your problem as the name of the relationship between your custom module and the Contacts one is feedback_contacts_1.

    Hope it helps.



  • Thank you for your suggestion. 

    I changed my code to a new version, get rid off deprecate things.

    function createRelationsWithContacts($bean,$event, $arguments) {
             // Add contact to feedback
                             $account = BeanFactory::retrieveBean('Accounts', $bean->feedback_accountsaccounts_ida);
                             if ($account->load_relationship('contacts')){
                                       $contacts = $account->contacts->getBeans();
                                       $rel_name = 'feedback_contacts_1';
                                       foreach ($contacts as $contact){
                                                 $c = BeanFactory::newBean('Contacts');
  • Thank for your help.

    This solution not fit to my problem.

    I think this solution can be solve my another topic soon.  

    Thanks, M