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');

            contacts.fetch({
                relate: true,
                success: _.bind(function(data) {
                    var toAddresses = _.map(data.models, 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?

Sugar 7.7.0.1

Thanks,

M

Parents Reply Children
  • 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
                   if(!empty($bean->account_id)){
                             $account = new Account();
                             $account->retrieve($bean->{account_id});
                             $contacts = $account->get_linked_beans('contacts','Contact');
                             // Relationship name
                                            $rel_name = 'custom_module_contacts_1';
                             foreach ($contacts as $contact){
                                       $c = new Contact();
                                       $c->retrieve($contact->id);
                                       $c->load_relationship($rel_name);
                                       $c->$rel_name->add($bean->id);
                             }
                   }
      }

    M