on 12-16-2018 5:35 PM
Hi everyone,
I just created an odata service.
in web ide I created a page where I call data from my odata. it works fine since data are retrieved.
but then I try to update/create data in SAP back-end.
with following code, it works fine :
var oModel = this.getView().byId("pageId").getModel();
oModel.setHeaders({
"X-Requested-With" : "X"
});
var obj = {};
obj.Contrat = this.getView().byId("input0").getValue();
obj.Nom1Societe = this.getView().byId("input1").getValue();
oModel.create('/ContratC13Set', obj, {
success : function(oData, oResponse) {
debugger;// eslint-disable-line
alert("Record Created Successfully...");
},
error : function(err, oResponse) {
debugger;// eslint-disable-line
alert("Error while creating record - "
.concat(err.response.statusText));
}
});
But as i'm using binding with odata from this page, is there a standard way to update/create without specifying the fields I want to send ?
I want to use following method but without "hard coding" :
oModel.create(('/ContratC13Sets', oEntry, null, function(){
alert("Create successful");
},function(){
alert("Create failed");}));
let's say my entity is /ContratC13Set and my xml view is the following :
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:cd="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1" controllerName="Oa_solaire_C13.Oa_solaire_C13.controller.View_form2">
<Page xmlns="sap.m" id="pageId" floatingFooter="true" cd:w5g.dt.context="/ContratC13Set" title="{Designation}">
<headerContent>
<Button icon="sap-icon://action" tooltip="Share" id="button0_1544957331820"/>
</headerContent>
<content>
<VBox width="100%" direction="Column" id="vbox2">
<items>
<InputListItem xmlns="sap.m" type="Navigation" label="Contrat" id="item0">
<content>
<Input ariaLabelledBy="__item0-label" width="100%" id="input0" value="{Contrat}" cd:w5g.dt.context="/ContratC13Set"/>
</content>
</InputListItem>
</items>
</VBox>
<VBox width="100%" direction="Column" id="vbox3">
<items>
<Input xmlns="sap.m" value="{Nom1Societe}" id="input1" cd:w5g.dt.context="/ContratC13Set"/>
</items>
</VBox>
</content>
<footer>
<OverflowToolbar id="toolbar1">
<ToolbarSpacer/>
<Button type="Accept" text="Accept" activeIcon="sap-icon://save" press="onSave"/>
</OverflowToolbar>
</footer>
</Page>
</mvc:View>
Update of morning.
I found this :
https://archive.sap.com/discussions/thread/3454103
this seems nice but it is'nt what I want. it is a way of creating odata entry when saving but I wonder if there is a means to instantiate the creation in init method of controller, using binding in my view to fill in every field of my oData and triggering the method afterwards. that is to say in algorythm :
- method init : initializing my odata entity
- View : filling in every fields
- controller : launching saving event and creation method.
I don't want to fill in every entry of my oData in saving method because that way what is the use of binding every field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since I found some answers concerning previous post, here is an update.
What I succeed to do :
- reading existing entry from SAP table and filling corresponding fields in my View
- Modifying data by searching for each field 1 by 1
-> what i'm trying to do :
- initializing my view form oData model (new entry)
- filling the fields of my view
- saving the new data in the table with create method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.