Skip to Content

Create form i sapui5

Mar 14, 2017 at 03:05 PM


avatar image

Hello everyone, i started recently learning sapui5 to create applications FIORI.

I have a master-detail application that consumes an OData service.

I also have a "create form" in fragment named "DetailCreateMode.fragment.xml" that's

supposed to create notifications. Unfortunatly, it does not create them.

Here's my fragment :

<core:FragmentDefinition height="100%" width="100%" xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout"     xmlns:f="sap.ui.layout.form">
<f:SimpleForm id="iconTabFilter1form" minWidth="1024" editable="false" layout="ResponsiveGridLayout" labelSpanL="3" labelSpanM="3"
            emptySpanL="4" emptySpanM="4" columnsL="1">
                <Label text="Equipement" required="false"/>
                <Input name="Equnr" id="Equnr_id" valueLiveUpdate="true" liveChange="_validateSaveEnablement"
                enabled="false" visible="true"
                value="{ path: 'Eqktx', type: 'sap.ui.model.odata.type.String' , constraints:{ maxLength:18, nullable:false } }"/>

                <Label text="Désignation" required="true"/>
                <Input name="Qmtxt" id="Qmtxt_id"     valueLiveUpdate="true" liveChange="_validateSaveEnablement"
                enabled="true" visible="true"
                value="{ path: 'Qmtxt', type: 'sap.ui.model.odata.type.String' , constraints:{ maxLength:40, nullable:false } }"/>

                <Label text="Date Avis" required="true"/>
                <DatePicker id="Qmdat" displayFormat="short" change="_validateSaveEnablement"
                 value="{ path: 'Qmdat', type: 'sap.ui.model.type.Date', formatOptions: { style : 'long' }  }"/>    


Here's the button that saves :

<Button id="saveButton" press="saveChanges" icon="sap-icon://save"></Button>

And last but not least, here's my controller's function :

saveChanges: function() {
    var oModel = this.getView().getModel();
    var mNewEntry = {};

    mNewEntry.Equnr = sap.ui.getCore().byId("Equnr_id");
    mNewEntry.Qmtxt = sap.ui.getCore().byId("Qmtxt_id");
    mNewEntry.Qmdat = sap.ui.getCore().byId("Date Avis");
    oModel.create("/avisSet", mNewEntry, null, function(oData){
            "Created succesfully",{
            icon : sap.m.MessageBox.Icon.SUCCESS,
            title : "Dear User",
            styleClass : "sapUiSizeCompact"
    }, function(err){
            icon : sap.m.MessageBox.Icon.ERROR,
            title : "Dear User",
            styleClass : "sapUiSizeCompact"

If i take a guess, i'd say that the values mNewEntry.Equnr, ... are undefined

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

1 Answer

Jun Wu Mar 14, 2017 at 03:28 PM

mNewEntry.Equnr =sap.ui.getCore().byId("Equnr_id");

    mNewEntry.Qmtxt =sap.ui.getCore().byId("Qmtxt_id");
    mNewEntry.Qmdat =sap.ui.getCore().byId("Date Avis");

never do this.

use model binding.

10 |10000 characters needed characters left characters exceeded