cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 - Import .CSV into OData Model - Error

savoine
Explorer
0 Kudos

Hi,

When you display import error, the error message for all records

I'm importing the records from a .CSV file into an oData Model and if the records do not have any errors they import normally, but if one of the records has an error it considers the same record for all create options.

onImportCSV: function(event) {
            var self = this;
            var oModelAdmin = this.getModel("admin");
            var oView = this.getView();
            var oTable = oView.byId("idTable");
            var aIndices = oView.byId("idTable").getSelectedIndices();
            oMessages = [];                        
            
            if (aIndices.length < 1) {
                MessageToast.show("Não existem items selecionados");
            } else {
                for(var i = 0; i < aIndices.length; i++ ) {
                    var oEntry = {};
                    oEntry.id = oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[0].getText();
                    oEntry.nome = oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[1].getText();
                    oEntry.email = oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[2].getText();
                    oEntry.ativo = oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[3].getText();
                    oEntry.super_usuario = oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[4].getText();
                    oEntry.csv = "1";
                    oModelAdmin.create("/Usuario", oEntry, {
                        success: function(data) {
                            MessageToast.show("Usuário (" + oEntry.id + ") salvo com sucesso!!!");                            
                        },
                        error: function(error) {
                            console.log(oEntry);
                            MessageToast.show("[" + error.statusCode + " - " + error.statusText + "] " + error.responseText);                                          }
                    });                        
                }
            }
        }

Because it ignores the correct record and applies the failed record to all interactions

Sorry for bad english.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member340030
Contributor
0 Kudos

Hi,

Why are you getting the table data like this .. ?? Why are you not using models ??

thanks

Viplove

savoine
Explorer
0 Kudos

Because I am importing the data from a .CSV file and want to append them in the OData service.

former_member340030
Contributor
0 Kudos

But these code statements doesnt seems that the values are from excel .. below means you are getting the table control ..

var oTable = oView.byId("idTable");

savoine
Explorer
0 Kudos

This is because I import the excel data into a table and then I select which records I want to write to the ODATA service

former_member340030
Contributor
0 Kudos

Oh than how did you import, you might have read the data from excel and bind it to the table using models ? Correct ?? if thats the case than you can get the items which you select and than for each item you can get the bindingContext to get the values and than add it to the odata request ..

This is how you need to do it ..