Skip to Content
avatar image
-1
Former Member

oModel.read(sPath) is not working properly

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 13, 2017 at 07:13 AM

    Hello Bala Manchikalapat,

    On which events you bind two functions onPress and onItemPress?

    Could you please post the xml view?

    Regards,

    Tri

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 13, 2017 at 07:46 AM

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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

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

    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>

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 14, 2017 at 04:55 AM

    Onpress you just filtering not reading...

    Check what error your getting in network tab,

    And check if get entity is implemented in the service.

    Add comment
    10|10000 characters needed characters exceeded