Skip to Content
-1

oModel.read(sPath) is not working properly

Jul 12, 2017 at 08:08 PM

352

avatar image
Former Member

Hi Experts,

oModel.read is failing ( onItemPress) , but working at (onPress)

and I am not able to see any Success message at onItemPress in Console after I click on one of the Item in First Screen.

Here is the FirstView.controller.js

sap.ui.controller("NavigationDemo1.navigationdemo.FirstView",

{ onInit: function() { var oModel = new sap.ui.model.odata.v2.ODataModel(this.getServiceUrl("/sap/opu/odata/SAP/ZNAMES_SRV_01/"));

oModel.read("/NM_ETT001Set",{ success : function(oData,response){ console.log("Success" +oData.results) }, error : function(oError){ console.log("Error" +oError.responseText) } });

this.getView().setModel(oModel); },

onPress : function(){ var from = this.getView().byId("idSelectFrom").getSelectedItem().getText();

var to = this.getView().byId("idSelectTo").getSelectedItem().getText();

var filter = [];

var myFilter = new sap.ui.model.Filter("Class", sap.ui.model.FilterOperator.BT, from, to); filter.push(myFilter); this.getView().byId("idList").getBinding("items").filter(filter);

},

onItemPress : function(oEvent) {

var selectedBname = oEvent.getSource().getTitle();

var oModel = this.getView().getModel();

var sPath = "/NM_ETT001Set('"+ selectedBname +"')";

/* here sPath has value /NM_ETT001Set('BALA')

var that = this;

oModel.read(sPath, {

/* Here it is not giving Success Message

success : function(oData, oResponse) { console.log("Success" +oData.results);

}

});

}

});

Please help .

With Regards, Bala

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

avatar image
Former Member Jul 14, 2017 at 02:50 PM
-1

I am able to resolve few issues , but Lastly when i select on list items, it should display details on that perticular item below, but it display the Label and not the data.( Please see the attachment ).

Here is my controller code :

onItemPress : function(oEvent)
{ var selectedBname = oEvent.getSource().getTitle();
var oModel = this.getView().getModel();
var sPath = "/QT_ETT001Set('"+ selectedBname +"')"; // here I am able to see the selected Line information
var that = this;
var oModel2 = new sap.ui.model.odata.v2.ODataModel(this.getServiceUrl("/sap/opu/odata/SAP/ZQT_NAMES_SRV_02/")); oModel2.read(sPath, {
success : function(oData,oResponse)
{
var osf = that.getView().byId("idSf");
osf.setVisible(true);
osf.setModel(oModel2);
console.log("Success");
sap.m.MessageToast.show("Data Read Successfully");
},
error : function(oError){
console.log("Error" +oError.responseText)
} });capture.jpg


capture.jpg (22.7 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 13, 2017 at 07:13 AM
0

Hello Bala Manchikalapat,

On which events you bind two functions onPress and onItemPress?

Could you please post the xml view?

Regards,

Tri

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 13, 2017 at 07:46 AM
0

Hi Bala,

it's missing binding..

in your code:-

onInit: function() { var oModel = new sap.ui.model.odata.v2.ODataModel(this.getServiceUrl("/sap/opu/odata/SAP/ZNAMES_SRV_01/"));

oModel.read("/NM_ETT001Set",{ success : function(oData,response){ console.log("Success" +oData.results) }, error : function(oError){ console.log("Error" +oError.responseText) } });

this.getView().setModel(oModel);

seems you have not binded, oModel to UI..any controls..

if you perform binding then there is a change of model.read..

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for your kind words.

What I mean to say unless your omodel gets binded the data will not travel though,. I'm not sure. But check it.

0
Former Member

Devendra garu,

I am able to resolve few issues , but Lastly when i select on list items, it should display details on that perticular item below, but it display the Label and not the data.

Here is my controller code :

onItemPress : function(oEvent)
{ var selectedBname = oEvent.getSource().getTitle();
var oModel = this.getView().getModel();
var sPath = "/QT_ETT001Set('"+ selectedBname +"')"; // here I am able to see the selected Line information
var that = this;
var oModel2 = new sap.ui.model.odata.v2.ODataModel(this.getServiceUrl("/sap/opu/odata/SAP/ZQT_NAMES_SRV_02/")); oModel2.read(sPath, {
success : function(oData,oResponse)
{
var osf = that.getView().byId("idSf");
osf.setVisible(true);
osf.setModel(oModel2);
console.log("Success");
sap.m.MessageToast.show("Data Read Successfully");
},
error : function(oError){
console.log("Error" +oError.responseText)
} });capture.jpg

capture.jpg (22.7 kB)
0
Former Member

Check binding with diognatic tool by pressing ctrl +shift +alt+s on chrome, select control tre, with in navigate to elements where binding is missing, it will help where the binding is missing.

Also search for how to use diognatic tool for sapui

0
avatar image
Former Member Jul 13, 2017 at 01:55 PM
0

Hi devender ( SAP Fiori Guru ),

Happy to see your response and I am proud to be a part of your follower, Never thought of such a great person like you will respond to me.

The error is in onItemPress: the cursor is not going inside of Success or error and not writing any log in console.

oModel.read(sPath, {

/* Error is @ this point.

success : function(oData, oResponse) { console.log("Success" +oData.results);

}

Hi Tri,

onItemPress.

onInit and onPress it is working fine.:

Here is my FirstView.view.xml:

http://www.w3.org/1999/xhtml">

<Page title="NM Details">
<List items="{ path : '/NM_ETT001Set', parameters : { select : 'Bname,Class'} }"
headerText="NM List" id="idList" growing="true" growingThreshold = "5">
<infoToolbar> <Toolbar design="Transparent">
<Label text="From"/>
<Select items="{ path : '/NM_ETT001Set'}" id="idSelectFrom">
<items> <c:Item text="{Class}"/>
</items>
</Select> <Label text=" To"/>
<Select items="{ path : '/NM_ETT001Set' }" id="idSelectTo">
<items> <c:Item text="{Class}"/>
</items>
</Select>
<Button text="Filter" type="Accept" press="onPress" />
</Toolbar> </infoToolbar>
<items> <StandardListItem title="{Bname}" description="{Class}" type="Active" press="onItemPress"/>
</items>
</List>

<VBox> <f:SimpleForm
id="idForm"
visible="false"
minWidth="1024"
maxContainerCols="2"
editable="false"
layout="ResponsiveGridLayout"
title="Address"
labelSpanL="3"
labelSpanM="3"
emptySpanL="4"
emptySpanM="4"
columnsL="1"
columnsM="1">
<f:content>
<Label text="User Name" />
<Text text="{/Bname}" />
<Label text="Department Name" />
<Text text="{/Class}" />
</f:content>
</f:SimpleForm>

</VBox>
</Page>
</core:View>

Share
10 |10000 characters needed characters left characters exceeded
Akhilesh Upadhyay Jul 14, 2017 at 04:55 AM
0

Onpress you just filtering not reading...

Check what error your getting in network tab,

And check if get entity is implemented in the service.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Akhilesh,

Sorry for the delay. Now I am able to read data into view, but when I press on Item, it should display Item details of it but Item text is display and not the data.

I am able to see the message in console
sap.m.MessageToast.show("Data Read Successfully");

Also on filter option , I am getting duplicate values. See the attachment Screenshot of issues and related code.

capture.jpg

view-and-controller.txt

duplicatesinfilter.png

0