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
  • Hi Martin,

    You could try, instead of using the function render, in the initialize function call another function like this:

    initialize: function(options) {
        this._super('initialize', [options]);
        this.model.on('sync', this.otherFunction, this);

    },

    otherFunction: function() {
    console.log(this.model.getRelatedCollection('contacts').length);
            console.log(this.model.get('to_addresses').length)
    }

    I dont know if this can work but you can try.

Reply
  • Hi Martin,

    You could try, instead of using the function render, in the initialize function call another function like this:

    initialize: function(options) {
        this._super('initialize', [options]);
        this.model.on('sync', this.otherFunction, this);

    },

    otherFunction: function() {
    console.log(this.model.getRelatedCollection('contacts').length);
            console.log(this.model.get('to_addresses').length)
    }

    I dont know if this can work but you can try.

Children
No Data