AnsweredAssumed Answered

Why isn't this.model referencing the drawer's model when it's open and how should this be approached?

Question asked by Artis Plocins on Apr 12, 2018
Latest reply on Apr 18, 2018 by John Hawkins

Through research, trial and error I've discovered that you can get the currently active drawer's actual context by using App.drawer.getActive().


This messes up custom fields and views where you want to use this.model to do something in the context of the model the view or the field is in, because if it is actually within a drawer - this.model is the model of the view behind the drawer, even if it's literally out of context!

// If this is run within a view or field that appears in a drawer over a record.
// Let's say it's a call record in a drawer over an account record (creating from the subpanel).
var callSubject = this.model.get('name') // Gets the name of the account in the background view.


Is there a better way, or would you say that indeed the best practice is to always do something like this in order to operate on the current model in a view or custom field?

// From within a view, probably in the initialize() function:
let drawer = app.drawer.getActive();
this.currentModel = drawer ? drawer.model : this.model;