Skip to Content
avatar image
Former Member

SAP UI5 - Import .CSV into OData Model - Error

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.

odata-error.jpg (96.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • May 04 at 06:55 AM

    Hi,

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

    thanks

    Viplove

    Add comment
    10|10000 characters needed characters exceeded

    • 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 ..