cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - oData Simple Form Binding

02-03-2019 11:08 PM
4163 views 4 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi Experts,

I'm trying to retrieve an OData model from inside onInit function of controller in SAPUI5 to access a property into a local variable.

I need “UserID” to define the sPath("/UserSets('SHARM2')")in order to bind it to Simple Form control using the following statement.

this.getView().byId("SimpleForm").bindElement("/UserSets('SHARM2')")

It’s a simple UI5 Update data form for current user logged in. I have tried to use “oModel.read” and “oModel.attachrequestcompleted” but since data loading is asynchronous, “UserID” is not available for form binding.

Please help.

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor
0 Likes

Hi Yogesh Sharma

Yes oData V2 is asynchronous. So you need to read like below:

oModel.read("/EntitySetName('Key')",{
   success: function(mData){
        console.log(mData);
        // Here check the mData and below set the bind element
        this.getView().byId("SimpleForm").bindElement("/UserSets('SHARM2')")
      }.bind(this)
}); 

There are lot's of blogs & answers outthere which answers your query..

BR,

Mahesh

former_member811618
Discoverer
0 Likes

Thanks a lot Mahesh Bhai.

Best Regards,

Answers (2)

Answers (2)

Former Member

Thank you Mahesh. That worked !

Appreciate your response guys.

saurabh_vakil
Active Contributor
0 Likes

Have you tried binding the userid to the form control in the controller's onBeforeRendering function?