on 10-19-2018 9:51 AM
Hi all,
I have a issue with multiple odatas and a SAPUI5 application, i prepared a document with the problem:
Objective :
The objective of this document is to explain in a detailed manner the encountered problems,
while trying to display information using two diferent odata sources for a same View.
Descriptions :
Hana cloud platform.
Simple Web-IDE ( development using sapui5 ).
Two odata data Sources : The first using odata source conexion to Success Factors , the Second conexion to a hana database.
The aplication has one view and one controller , and several models ( wich we bind to diferent elements of the view)
We declared the datasource and model in the manifest.json :
The main service odata(Default )corresponds to the success factors
The second odata services.xsodata(afirme hana) corresponds to the hana database
Manifest.json
Manifest.json:
{
"_version": "1.9.0",
"sap.app": {
"id": "Afirme2.Afirme2",
"type": "application",
"i18n": "i18n/i18n.properties",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"mainService": {
"uri": "/odata/v2/odata/v2/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
},
"services.xsodata": {
"uri": "/hanaAfirme/afirmehanax6cbb2a2dc/afirmehana/services.xsodata/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/services.xsodata/metadata.xml"
}
},
"GWSAMPLE_BASIC": {
"uri": "/ES5/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/GWSAMPLE_BASIC/metadata.xml"
}
}
},
"sourceTemplate": {
"id": "servicecatalog.connectivityComponent",
"version": "0.0.0"
},
"crossNavigation": {
"inbounds": {}
}
},
"sap.ui": {
"technology": "UI5",
"icons": {
"icon": "sap-icon://task",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
}
},
"sap.ui5": {
"rootView": {
"viewName": "Afirme2.Afirme2.view.App",
"type": "XML",
"async": true,
"id": "app"
},
"dependencies": {
"minUI5Version": "1.42.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.f": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "Afirme2.Afirme2.i18n.i18n"
}
},
"": {
"dataSource": "mainService",
"preload": true,
"settings": {
"defaultCountMode": "Request",
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay"
}
},
"filtroCombobox": {
"type": "sap.ui.model.json.JSONModel",
"settings": {},
"preload": false,
"uri": "model/filtroCombobox.json"
},
"afirmeHana": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "TwoWay",
"defaultCountMode": "Request"
},
"dataSource": "services.xsodata",
"preload": true
},
"ES5": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay",
"defaultCountMode": "Request"
},
"dataSource": "GWSAMPLE_BASIC",
"preload": true
}
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "Afirme2.Afirme2.view",
"controlId": "app",
"controlAggregation": "pages",
"bypassed": {
"target": ["notFound"]
},
"async": true
},
"routes": [{
"pattern": "",
"name": "worklist",
"target": ["worklist"]
}, {
"pattern": "User/{objectId}",
"name": "object",
"target": ["object"]
}, {
"name": "object",
"pattern": "FODepartment/{objectId}",
"titleTarget": "",
"greedy": false,
"target": ["object"]
}],
"targets": {
"worklist": {
"viewName": "Worklist",
"viewId": "worklist",
"viewLevel": 1,
"title": "{i18n>worklistViewTitle}"
},
"object": {
"viewName": "Object",
"viewId": "object",
"viewLevel": 2,
"title": "{i18n>objectViewTitle}"
},
"objectNotFound": {
"viewName": "ObjectNotFound",
"viewId": "objectNotFound"
},
"notFound": {
"viewName": "NotFound",
"viewId": "notFound"
}
}
}
}
}
View:
View:
<mvc:View
controllerName="Afirme2.Afirme2.controller.App"
xmlns:l="sap.ui.layout"
xmlns:core="sap.ui.core"
xmlns:u="sap.ui.unified"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
xmlns:semantic="sap.m.semantic"
xmlns:form="sap.ui.layout.form">
<semantic:FullscreenPage>
<ObjectHeader
id="objectHeader"
title ="Nombre : {userapi>/name}"
responsive="true"
>
<attributes>
<ObjectAttribute />
</attributes>
</ObjectHeader>
<Panel
class="sapUiResponsiveMargin"
width="auto"
headerText="Programar visitas sucursales"
expandable="{device>/system/phone}"
expanded="true"
backgroundDesign="Solid"
>
<content>
<l:VerticalLayout>
<Label id="nombreUsuario" text="{userapi>/name}" visible="false"></Label>
<InputListItem label="Tipo sucursal que deseas visitar">
<ComboBox
selectionChange="onSelect"
selectedKey="{/selectedKey}"
id="tipoSucursal"
items="{
path: '/PickListValueV2',
sorter: { path: 'externalCode' }
,
filters : [
{ path : 'PickListV2_id', operator : 'EQ', value1 : 'sucursal'},
{ path : 'externalCode', operator : 'EQ', value1 : '1' },
{ path : 'externalCode', operator : 'EQ', value1 : '2'},
{ path : 'externalCode', operator : 'EQ', value1 : '3'}
]
}">
<core:Item key="{externalCode}" text="{label_defaultValue}" />
</ComboBox>
</InputListItem>
<InputListItem label="Sucursal que deseas visitar">
<ComboBox
id="Sucursal"
items="{
path: '/FODepartment',
sorter: { path: 'cust_tipoSucursal' }
}">
<core:Item key="{cust_tipoSucursal}" text="{name}" />
</ComboBox>
</InputListItem>
<u:Calendar
id="calendar"
select="handleCalendarSelect" />
<Text
id="selectedDate"
text="No Date Selected"
class="labelMarginLeft"/>
<Button
press="VisitasProgramdas"
text="VisitasProgramdas" />
<Button
press="Registrar"
text="Registrar" />
</l:VerticalLayout>
</content>
</Panel>
</semantic:FullscreenPage>
</mvc:View>
Controller.js
Controller:
sap.ui.define(['sap/ui/core/mvc/Controller','sap/ui/unified/DateRange','sap/ui/model/json/JSONModel','sap/ui/model/Filter'],
function(Controller, DateRange,JSONModel) {
"use strict";
var CalendarSingleDaySelectionController = Controller.extend("Afirme2.Afirme2.controller.App", {
oFormatYyyymmdd: null,
onInit: function() {
this.oFormatYyyymmdd = sap.ui.core.format.DateFormat.getInstance({pattern: "yyyy-MM-dd", calendarType: sap.ui.core.CalendarType.Gregorian});
this.getUser();
// this.disableDate();
},
getUser:function(){
var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
this.getView().setModel(userModel, "userapi") ;
},
disableDate:function(){
var oModel = new JSONModel();
oModel.setData({
minDate: new Date(2018, 0, 1),
maxDate: new Date(2050, 11, 31),
disabled: [{start: new Date(2018, 0, 4), end: new Date(2018, 0, 18)},
{start: new Date(2016, 0, 15)}
]
});
this.getView().setModel(oModel);
},
handleCalendarSelect: function(oEvent) {
var oCalendar = oEvent.oSource;
this._updateText(oCalendar);
},
_updateText: function(oCalendar) {
var oText = this.byId("selectedDate");
var aSelectedDates = oCalendar.getSelectedDates();
var oDate;
if (aSelectedDates.length > 0 ) {
oDate = aSelectedDates[0].getStartDate();
oText.setText("Has Elegido la fecha " + this.oFormatYyyymmdd.format(oDate));
} else {
oText.setValue("No Date Selected");
}
},
onSelect : function(oEvent){
var idItem = this.byId("tipoSucursal").getSelectedKey();
this.getView().byId("Sucursal").getBinding("items").filter([
new sap.ui.model.Filter(
"cust_tipoSucursal",
"EQ",
idItem )
]);
/* var filtro = this.getOwnerComponent().getModel("filtroCombobox");
filtro.setData({
recipient : {
clave : idItem
}
}); */
// console.log(filtro.getProperty("/recipient/clave"));
// console.log("he cambiado"+idItem);
},
Registrar: function(oEvent) {
var oCalendar = this.byId("calendar");
var aSelectedDates=oCalendar.getSelectedDates();
var oDat2e = aSelectedDates[0].getStartDate();
var dia = oDat2e.getDate()+1.;
var mes = oDat2e.getMonth();
var year = oDat2e.getFullYear();
var fecha2 = new Date(year,mes,dia);
// var fechaFinal = this.oFormatYyyymmdd.format(oDat2e);
console.log(fecha2);
var varTipoSucursal = this.getView().byId("tipoSucursal").getSelectedItem().getText();
var varSucursal = this.getView().byId("Sucursal").getSelectedItem().getText();
var nombreUser = this.getView().byId("nombreUsuario").getText();
// var prueba = this.getOwnerComponent().getModel("afirmeHana");
// var oModel = this.getView().getModel();
var mNewEntry = {};
mNewEntry.idVisitaProgramada = Math.floor(Date.now() / 1000);
mNewEntry.Fecha= new Date(year,mes,dia);
mNewEntry.TipoSucursal = varTipoSucursal;
mNewEntry.Sucursal = varSucursal;
mNewEntry.Usuario = nombreUser;
this.getOwnerComponent().getModel("afirmeHana").create("/VisitaProgramada", mNewEntry, null);
this.getOwnerComponent().getModel("afirmeHana").submitChanges();
}
});
return CalendarSingleDaySelectionController;
});
Description of the main issue:
At the moment that we want to bind the second model (afirmeHana )->( services.xsodata),
The view displays blank fields.
<Label
id="nombreUsuario" text="{afirmeHana>/Visitasprogramadas/0/Usuario}"
visible="true"></Label>
…
<Label
id="nombreUsuario"
text="{afirmeHana>/Visitasprogramadas/Usuario }" visible="true"></Label>
-Observations:
If we switch the main datasource (mainService) and model (Default) for the secondary odata data source(afirmeHana)
The binding Works in for the secondary model(afirmeHana) and stops working for the previous default model (main Service)
This way we know that we are able to retrieve information using one model or the other model, but not both at the same time.
We have checked that the Entity names are correct, that the tables have information.
Thanks in advance.
Best Regards.
{afirmeHana>/Visitasprogramadas/0/Usuario} you cannot bind odata model like this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.