Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sap.ui.getCore().byId() returns no element

Tags:

sapui5

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?

like image 365
pguddi Avatar asked Dec 05 '25 13:12

pguddi


1 Answers

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).

like image 71
sirion Avatar answered Dec 07 '25 16:12

sirion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!