I created an UI5 app and now want to use sap.ui.getCore().byId(id) to access existing controls. In the same controller/view I can access them via this.byId(id), but to access controls in other files (e.g. controllers) I need sap.ui.getCore().byId(id).
However, while sap.ui.getCore() returns a core object, I cannot access controls via the byId() function of it, I get undefined instead. I already built an UI5 app and there I have no issue with this function call.
Is there something I have to configure for this to work?
If you look into the view's byId-method, you can see that it prepends the views ID, it essentially calls sap.ui.getCore().byId(this.createId(id)).
This is so that you can instantiate a view several times without having duplicate IDs. In order to access the controls from the outside, you either need the view so you can call view.byId(id), or you have to manually concatenate the view's ID with the ID like this: sap.ui.getCore().byId(viewId + "--" + id).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With