Skip to Content
0

SAP UI5 - Import .CSV into OData Model - Error

May 03 at 03:20 PM

74

avatar image
Former Member

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

VIPLOVE KHUSHALANI May 04 at 06:55 AM
0

Hi,

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

thanks

Viplove

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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");

0
Former Member

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

0

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

0