How to add cc emails to new email

Hello,

  I need to find a way to include the people that are CC'ed in an email to appear when they email form the record view.

They then click the plus btn to generate a new email and this div appears to do that.

How would I start the process of automatically adding the CC'ed peoples to this view?

So to clarify I want the people that were CC'ed before in the case's history to automatically appear when clicking the plus btn and the user won't need to do it manually then.

Best Regards

James Palmisano

  • Hehe yes I have my work cut out for me. Thank you for your help. 

  • So I believe that the code for producing the email in ./include/workflow/alert_util.php which appears to be a stock class from sugar.  So how l would I go about extending on that?  Or maybe just file this problem away for now and come back to it later when I have more thoughts on the subject.  

  • Looks like you are using the Workflow module to generate the email and the service rep doesn't even see the email...

    The workflow will have a condition like email the contacts related to the case or some such (I don't use Workflow so I'm not too familiar with it - I prefer logic_hooks and the Professional version I'm on won't have Workflow in the near future)...

    Using Workflow you need to have all your Cc's related to the Case - I forget if the stock Cases allows for multiple contacts on a case or not, but if the Cc is an address not related to a Contact you won't be able to pull it...

    One option: replace the workflow with a logic hook, when the note is saved trigger a logic hook to generate an email and include the Cc's by using the query we discussed earlier. There are a few examples out there of how to send emails from sugarCRM using code.

    Read up on logic hooks here:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Logic_Hooks/

  • NOTE:

    the sender.js code above breaks in 7.8 Pro

    This works in 7.8 Pro

    ({
        fieldTag: 'input.select2',
        initialize: function(options) {
            this._super('initialize',[options]);
            this.endpoint = this.def.endpoint;
        },
        _render: function() {
            var result = app.view.Field.prototype._render.call(this);
            if (this.tplName === 'edit') {
                var action = (this.endpoint.action) ? this.endpoint.action : null,
                    attributes = (this.endpoint.attributes) ? this.endpoint.attributes : null,
                    params = (this.endpoint.params) ? this.endpoint.params : null,
                    myURL = app.api.buildURL(this.endpoint.module, action, attributes, params);
                app.api.call('GET', myURL, null, {
                    success:  _.bind(this.populateValues, this),
                    error: function(error) {
                        // display error if not a metadata refresh
                        if (error.status !== 412) {
                            app.alert.show('server-error', {
                                level: 'error',
                                messages: 'ERR_GENERIC_SERVER_ERROR'
                            });
                        }
                        app.error.handleHttpError(error);                }
                });
            }
            return result;
        },
        populateValues: function(results) {
            var self = this,
                defaultResult,
                defaultValue = {},
                parentMod = self.context.parent,
                parentModule = parentMod.get('module'),
                q = parentMod.get('model').get('case_queue_c');
                if(!_.isUndefined(q) && !_.isEmpty(q)) var queue = ('('+q+')').replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
            if (this.disposed === true) {
                return; //if field is already disposed, bail out
            }
            if (!_.isEmpty(results)) {
                if(parentModule == 'Cases' && !_.isUndefined(queue) && !_.isEmpty(queue)){
                  var pattern = new RegExp('.*'+queue+'.*');
                  defaultResult = _.find(results, function(result) {
                    return result.display.match(pattern);
                  });
                }else{
                  defaultResult = _.find(results, function(result) {
                    return result.default;
                  });
                }
                defaultValue = (defaultResult) ? defaultResult : results[0];
                if (!this.model.has(this.name)) {
                    this.model.set(this.name, defaultValue.id);
                }
            }
            var format = function(item) {
                return item.display;
            };
            this.$(this.fieldTag).select2({
                data:{ results: results, text: 'display' },
                formatSelection: format,
                formatResult: format,
                width: '100%',
                placeholder: app.lang.get('LBL_SELECT_FROM_SENDER', this.module),
                initSelection: function(el, callback) {
                    if (!_.isEmpty(defaultValue)) {
                          callback(defaultValue);
                    }
                }
            }).on("change", function(e) {
                if (self.model.get(self.name) !== e.val) {
                    self.model.set(self.name, e.val, {silent: true});
                }
            });
        },

      /**
       * {@inheritdoc}
       *
       * We need this empty so it won't affect refresh the select2 plugin
       */

      bindDomChange: function() {
      }
    })
  • Hello, 

    Sharing a piece of code that gets the emails from the Emails Widget within the record and place them into the TO (if primary) and CC fields (if not primary).

    Hope you find it useful as well.

    Regards, 

    Angel M.



    ({
       extendsFrom: 'EmailsComposeEmailView',

       initialize: function(options){
       this._super('initialize',[options]);
       this.configureDefaults();
    },

    /**
    * Configure the default data
    */
    configureDefaults: function(){
        var model = this.context.parent.get('model');
        var module = this.context.parent.get('module');
        var email = this.model;
        if (module == 'Accounts'){
           if (email.attributes.parent.email.length >= 2) {
           var CBFirstName = model.get('cai_first_name_c');
           var CBLastName = model.get('cai_last_name_c');
           var CBName = CBFirstName.concat(" ", CBLastName);

           emails = email.attributes.parent.email;
           toRecords = [];
           emails.forEach(function (record){
              if(emails[0].email_address != record.email_address){
                 toRecords.push(App.data.createBean('EmailParticipants', {
                 _link: "to",
                 parent_type: "Accounts",
                email_address: record.email_address,
                email_address_id: record.email_address_id,
                parent_name: CBName
                 }));
              }else{
                 ccRecords.push(App.data.createBean('EmailParticipants', {
                 _link: "cc",
                 parent_type: "Accounts",
                 email_address: record.email_address,
                 email_address_id: record.email_address_id,
                 parent_name: CBName
                 }));
              }
           });
           email.get('to_collection').add(toRecords);
           email.get('cc_collection').add(ccRecords);

           }
        }
        }
    })