Create Email (compose.js) - how do I access the pre-populated contacts from the render function?

Hello, 

For context: I am attempting to extend compose.js to set up some default values based on the number of contacts initially added. I am creating the email from the email subpanel on a case, which adds the case contacts into the email recipients by default.

The following code sample illustrates my problem: 

({
    extendsFrom: 'BaseEmailsComposeView',

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

    _render: function () {
        this._super("_render");

        // These lines show as 0 in the console.
        console.log(this.model.getRelatedCollection('contacts').length);
        console.log(this.model.get('to_addresses').length);
    }
})

The console output always shows 0 regardless of how many recipients. How can I retrieve the initial recipients? 

Thanks very much,

Martin

Parents
  • Hello Francesca, Hello Salvador, 

    Thanks very much for your responses. 

    I've tried both with no luck unfortunately. It looks like the 'sync' event is never fired having put this in my initialize function: 

    this.model.on('all', function (event) {
        console.log(event);
    })

    Could it be something unique about BaseEmailsComposeView? I know its a special case because Email is a backward compatibility mode module. 

    Any other thoughts are much appreciated. 

Reply
  • Hello Francesca, Hello Salvador, 

    Thanks very much for your responses. 

    I've tried both with no luck unfortunately. It looks like the 'sync' event is never fired having put this in my initialize function: 

    this.model.on('all', function (event) {
        console.log(event);
    })

    Could it be something unique about BaseEmailsComposeView? I know its a special case because Email is a backward compatibility mode module. 

    Any other thoughts are much appreciated. 

Children
No Data