on 2024 Aug 08 9:48 PM
Good afternoon community, first of all thank you very much for your help. I am having a problem, I have an OData v4 service exposed with two entities: "Auditoria" and "TipoAuditoria", both are related. I show you two objects:
Auditoria
{
"ID": "1b2c3d4a-7f6e-5d3b-1c2a-9f8e7d6c5a2b",
"DESCRIPCION": "Evaluación de control interno",
"TIPOAUDITORIA_ID": "c1e9b7a0-91f4-4e2c-bb1a-0f524f6b6d51"
}
TipoAuditoria:
{
"ID": "c1e9b7a0-91f4-4e2c-bb1a-0f524f6b6d51",
"DESCRIPCION": "Auditoría Interna"
}
As you can see both objects are very simple.
I'm creating a Fiori app using the basic template. So I'm setting up my table completely from scratch. I'll show you the code for my table:
<f:content>
<Table
id="auditoriaTable"
growing="true"
growingThreshold="10"
items="{
path:'/Auditoria',
parameters: {
$count: true,
$$updateGroupId: 'auditoriaGroup'
}
}"
mode="SingleSelectLeft">
<headerToolbar>
<OverflowToolbar>
<content>
<ToolbarSpacer/>
<Button
id="addAuditoria"
icon="sap-icon://add"
tooltip="{i18n>createAuditoriaButton}"
press="onCreate"
type="Emphasized"
/>
<Button
id="deleteAuditoria"
icon="sap-icon://delete"
tooltip="{i18n>deleteAuditoriaButton}"
press="onDelete"
type="Negative"
/>
<Button
id="sortAuditoria"
icon="sap-icon://sort"
enabled="{= !${viewModel>/hasUIChanges}}"
tooltip="{i18n>sortAuditoriaButton}"
press="onSort"
type="Emphasized"
/>
<Button
id="clearFilters"
icon="sap-icon://clear-filter"
tooltip="{i18n>clearAuditoriaButton}"
press="onClearFilters"
type="Emphasized"
/>
</content>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column
hAlign="Begin"
minScreenWidth="Small"
demandPopin="true">
<Text text="{i18n>tableDescripcionAuditoria}"/>
</Column>
<Column
hAlign="Begin"
minScreenWidth="Small"
demandPopin="true">
<Text text="{i18n>tableTipoAuditoria}"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Input
value="{DESCRIPCION}"
liveChange="onInputChange"/>
<ComboBox
id="comboId"
items="{
path:'/TipoAuditoria',
templateShareable: true
}"
selectedKey="{ID}"
selectionChange="onInputChange"
>
<items>
<core:Item key="{ID}" text="{DESCRIPCION}" />
</items>
</ComboBox>
</cells>
</ColumnListItem>
</items>
</Table>
</f:content>
My create button:
<Button
id="addAuditoria"
icon="sap-icon://add"
tooltip="{i18n>createAuditoriaButton}"
press="onCreate"
type="Emphasized"
/>
The login in the Controller:
onCreate: function () {
let oList = this._oAuditoriaTable;
let oBinding = oList.getBinding("items");
let oContext = oBinding.create({
"DESCRIPCION": "",
"TIPOAUDITORIA_ID": ""
});
this._setUIChanges();
this.getView().getModel("viewModel").setProperty("/auditoriaEmpty", true);
oList.getItems().some(function (oItem) {
if (oItem.getBindingContext() === oContext) {
oItem.focus();
oItem.setSelected(true);
return true;
}
});
}
My save button:
<Button
id="saveButton"
text="{i18n>saveButton}"
press="onSave"
type="Success"
/>
The login in the Controller:
onSave: function () {
const fnSuccess = function () {
this._setBusy(false);
this._setUIChanges(false);
MessageToast.show(this._getText("changesSentMessage"));
}.bind(this);
const fnError = function (oError) {
this._setBusy(false);
this._setUIChanges(false);
MessageToast.error(oError.message);
}.bind(this);
this._setBusy(true);
this.getOwnerComponent()
.getModel()
.submitBatch("auditoriaGroup")
.then(fnSuccess, fnError);
}
Now, the problem I'm having is that the ID value of my ComboBox from the TipoAudiatoria entity is not being saved in the new entity I want to create, it arrives empty. I don't know what I'm doing wrong.
The error that the console throws:
Log-dbg.js:497 2024-08-08 17:44:37.658399 POST on 'Auditoria' failed; will be repeated automatically - Deserialization Error: Invalid value (string) for property "TIPOAUDITORIA_ID". A string value in the format 8HEXDIG-4HEXDIG-4HEXDIG-4HEXDIG-12HEXDIG must be specified as value for type Edm.Guid.
Error: Communication error: 400 Bad Request
at Object.createError (https://port8080-workspaces-ws-2xrdg.us10.trial.applicationstudio.cloud.sap/resources/sap/ui/core/library-preload.js:2322:3817)
at https://port8080-workspaces-ws-2xrdg.us10.trial.applicationstudio.cloud.sap/resources/sap/ui/core/library-preload.js:2352:11536
at Array.forEach (<anonymous>)
at a (https://port8080-workspaces-ws-2xrdg.us10.trial.applicationstudio.cloud.sap/resources/sap/ui/core/library-preload.js:2352:11244)
at https://port8080-workspaces-ws-2xrdg.us10.trial.applicationstudio.cloud.sap/resources/sap/ui/core/library-preload.js:2352:12323 sap.ui.model.odata.v4.ODataListBinding
The batch / Request payload:
The curious thing is that it saves in ID the value that should go in TIPOAUDITORIA_ID, given that the ID must be automatically generated by the database.
Check line#76 of you view.xml. Shouldn't this be TIPOAUDITORIA_ID?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.