Hello Experts,
I am trying to map oData output to simple form fields. For this, I have defined the oData model in manifest.json as follows.
"dataSources": {
"employeesDS": {
"uri": "/sap/opu/odata/sap/ZFAH_GW_CRUDQ_USERS_1_SRV/",
"type": "OData",
"settings": {
"annotations": [],
"odataVersion": "2.0",
"localUri": ""
}
}
}
....
"models": {
"i18n": {
...
},
"myOModel": {
"dataSource": "employeesDS",
"settings": {
"defaultBindingMode": "TwoWay"
}
}
The JSON output of /sap/opu/odata/SAP/ZFAH_GW_CRUDQ_USERS_1_SRV/EmployeeSet('1000000002') is as follows
{
"d" : {
...
},
"Empid" : "1000000002",
"Empname" : "Rehna",
"Empadd" : "B",
"Empdesc" : "B"
}
}
View binding is done as follows:
<Label text="Employee ID" id="EmapID_label"/>
<Input width="100%" id="EmpID_input" value="{myOModel>/Empid}"/>
<Label text="Name" id="Name_label"/>
<Input width="100%" id="Name_input" value="{myOModel>/Empname}"/>
I have invoked it from Component.js (during form load for testing purpose) as follows:
init: function() {
...
var oModel = this.getModel("myOModel");
var oMetadata = oModel.getServiceMetadata();
console.log(oMetadata);
oModel.attachMetadataLoaded(null, function(){
var oMetadata = oModel.getServiceMetadata();
console.log("oMetadata loaded successfully:"+oMetadata); },
null);
oModel.read("/EmployeeSet('1000000001')", {
success: function(oData, response){
MessageToast.show("Success");
this.setModel(oData,"myOModel");
alert("success by oModel.read event handler");
}
Here, console.log(oMetadata) is showing some results which indicates the oData service call is successful.
However, I am getting error in the following line of success event handler
this.setModel(oData,"myOModel");
Error message in chrome log says: Cannot read property 'setModel' of undefined.
By writing this.setModel(oData,"myOModel"), I was trying to set the result retrieved from oData back to the Component.js model so that view fields will display the corresponding values (from myOModel). However, I am wondering how "this" can be undefined!!
Please note that I am trying this with latest WebIDE. Can you please let me know what I am doing wrong here? Also, is this the right approach to invoke and bind oData model to view fields?
Thanks,
Faddy