Trouble fetching related in record.js

Hello I am having a bit of trouble with getting data from a relate field in a custom record.js file. Below I have the code sample. I've been trying different data:sync:complete and render triggers. The function is called but I can't get the data out. 

this.collection.on('data:sync:complete', this.getRelatedFields, this);
this.model.on('data:sync:complete', this.getRelatedFields, this);
getRelatedFields: function () {
    var self = this;
    var closing_notary_id = self.model.get('apps_notaries_id1_c');
    debugger;
    if (!_.isEmpty(closing_notary_id)) {
        var closing_notary = app.data.createBean('apps_Notaries',{id: closing_notary_id});
        closing_notary.fetch();
        var phone = closing_notary.get('phone_work');
        self.model.set('closing_notary_phone_c',phone);

    }
},

When I use the Chrome console and call at the break point I get. But it works if I wait until the page has finished loading.@

stash.min.js:2 Uncaught TypeError: Cannot read property 'apply' of undefined 

I could use an after_retrieve logic hook instead but was hoping to use sidecar.

Any assistance would be appreciated.

Parents
  • I am not sure where the apply comes into it, but try waiting for the fetch to complete successfully. It is not uncommon for the code beyond the fetch to execute before the fetch is complete.

       var closing_notary_id = self.model.get('apps_notaries_id1_c');
        debugger;
        if (!_.isEmpty(closing_notary_id)) {
            var closing_notary = app.data.createBean('apps_Notaries',{id: closing_notary_id});
            closing_notary.fetch({
              success: function(
                var phone = closing_notary.get('phone_work');
                self.model.set('closing_notary_phone_c',phone);
              },
              error: function(e){
                console.log(e);
              },
            });
        }

    HTH,

    FrancescaS

Reply Children
No Data