Skip to Content
0
May 03, 2018 at 03:20 PM

SAP UI5 - Import .CSV into OData Model - Error

289 Views

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.

Attachments

odata-error.jpg (96.8 kB)