Skip to Content
0
Jul 18, 2016 at 11:01 AM

"Uncaught TypeError: Cannot read property 'getValue' of undefined"

4027 Views

Hi all ,

I am trying to do CRUD operations using my own OData service which I was developed using WEB IDE and I have successfully read the data from back end and displayed in page as shown in below figure shown.

I have used Dialog for creating new user i.e CREATE in CRUD. But I am getting error as

"Uncaught TypeError: Cannot read property 'getValue' of undefined"

Please correct me.

Code:

Home.view.xml

<mvc:View controllerName="venky.ui5crud.controller.Home" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"

xmlns:l="sap.ui.layout" xmlns="sap.m">

<App>

<pages>

<Page title="{i18n>title}">

<content>

<Table id="idUsers" items="{/UserSet}" mode="SingleSelectLeft" class="sapUiResponsiveContentPadding">

<headerToolbar>

<Toolbar>

<Title text="Users" level="H2"/>

</Toolbar>

</headerToolbar>

<columns>

<Column width="12em">

<Text text="First Name"/>

</Column>

<Column width="12em">

<Text text="Last Name"/>

</Column>

<Column width="12em">

<Text text="Address"/>

</Column>

<Column width="12em">

<Text text="Email"/>

</Column>

</columns>

<items>

<ColumnListItem>

<cells>

<Text text="{Firstname}"/>

<Text text="{Lastname}"/>

<Text text="{Address}"/>

<Text text="{Email}"/>

</cells>

</ColumnListItem>

</items>

</Table>

</content>

<Button text="Create New User" press="onCreateData" />

</Page>

</pages>

</App>

</mvc:View>

Home.controller.js

sap.ui.define([

"sap/ui/core/mvc/Controller"

], function(Controller) {

"use strict";

return Controller.extend("venky.ui5crud.controller.Home", {

onCreateData: function() {

this._Dialog = sap.ui.xmlfragment("venky.ui5crud.view.CreateUser",

this);

this._Dialog.open();

},

onClose: function() {

this._Dialog.close();

},

onSave: function() {

var oEntry = {};

var inputEmail = this.getView().byId(this.createId("idIpEmail")).getValue(); //Error here

var inputFirstName = this.getView().byId(this.createId("idIpFname")).getValue();

var inputLastName = this.getView().byId(this.createId("idIpLname")).getValue();

var inputAddress = this.getView().byId(this.createId("idIpAddress")).getValue();

oEntry.Email = inputEmail;

oEntry.FirstName = inputFirstName;

oEntry.LastName = inputLastName;

oEntry.Address = inputAddress;

sap.ui.getCore().getModel().create("/UserSet", oEntry, null, function() {

sap.m.MessageBox.show("Success");

}, function() {

sap.m.MessageBox.show("Error!");

});

}

});

});

CreateUser.fragment.xml

<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:f="sap.ui.layout.form" xmlns:l="sap.ui.layout" xmlns="sap.m">

<Dialog title="Create User">

<f:SimpleForm id="idCreateUserForm" minWidth="1024" maxContainerCols="2" editable="true" layout="ResponsiveGridLayout" title="Address"

labelSpanL="3" labelSpanM="3" emptySpanL="4" emptySpanM="4" columnsL="1" columnsM="1" class="editableForm">

<f:content>

<Label text="Email ID"/>

<Input id="idIpEmail" value=""/>

<Label text="First Name"/>

<Input id="idIpFname" value=""/>

<Label text="Last Name"/>

<Input id="idIpLname" value=""/>

<Label text="Address"/>

<Input id="idIpAddress" value=""/>

</f:content>

</f:SimpleForm>

<beginButton>

<Button text="Save" type="Accept" press="onSave"/>

</beginButton>

<endButton>

<Button text="Close" type="Reject" press="onClose"/>

</endButton>

</Dialog>

</core:FragmentDefinition>

After clicking on "Create New User" button below Dialog appears which is a fragment.

Getting error when I click on Save button(green color).

Attachments

crud2.jpg (43.3 kB)
crud1.jpg (63.8 kB)