cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to set Text control from Odata service in SAPUI5 app

avisheksharmacoder
Participant
0 Kudos

Hi, I am doing a read operation and then trying to set the text of sap.m.Text control dynamically from Controller file. The read operation is triggered by the press of a Read button.

I am able to retrieve the data(from northwind service) but no luck setting the Text properly.

This is the Text control and Read Button.

this is controller code in a file.

fireread.txt

Do I need to use another method for this?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Dino
Explorer
0 Kudos

this is not defined in the success handler. you need to save it in a global var:
var that = this;
....

success:

....
that.getView().byId("t1").setText(textData);

....

avisheksharmacoder
Participant
0 Kudos

Thanks worked perfectly.

Answers (1)

Answers (1)

Dino
Explorer

The oModel2.read(...) is asynchronous. So the setText(textData) is done before the success function is called.

If you move this.getView().byId("t12).setText(textData) to the success function it should work as expected.

I would prefer to set the text of the text control by a binding.

avisheksharmacoder
Participant
0 Kudos

Yes, i already tried writing the setText() line inside success, but it is giving another error = "Cannot read properties of undefined (reading 'getView')", So i made a variable outside success and then set the ProductName to this variable, but that seems to be not working due to the async behavior. Isnt' there a way to assign the data, once the success executes, like metadataLoaded().