on 02-20-2019 11:42 AM
HI Friends
I am trying to upload csv file into HANA DB table. how ever while using onload function i am not able to make function call in order to push json variable as a parameter into other method where service call will be made to to HANA DB and record should be pushed.
1) if i use service call in onload function json variable is getting override and only 1 record is getting inserted.
2) was not able to call other method in order to avoid the issue
could you please suggest me on this
onUpload: function(oEvent){
pst=this.getView().byId('pid');
var oFileUploader = this.getView().byId('FUP');
var domRef = oFileUploader.getFocusDomRef();
var record =[]; var rowData = []; var data ; var gval= oFileUploader.getValue().toString();
var file = oFileUploader.oFileUpload.files[0];
var that = this; this.filename = file.name; this.filetype = file.type; this.len=0;
// Reading a CSV file
var reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function(e) {
var strCSV = e.target.result;
var rows = strCSV.split("\n");
var len = rows.length-1;
for(var i=0;i<this.len-1;i++){
console.log(this.len); debugger;
rowData=data[i+1].split(",");
if(rowData.length == 5){ //coulumns are 5
var dateStr = rowData[2];
var dateStrB = rowData[3];
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: 'yyyy/MM/dd'});
var TZOffsetMS = new Date(0).getTimezoneOffset()*60*1000;
var parseDate = new Date(oDateFormat.parse(dateStr).getTime()-TZOffsetMS);
var parseDateB = new Date(oDateFormat.parse(dateStrB).getTime()-TZOffsetMS);
var newData = {
"STR":rowData[0],
"SK_PHASE":rowData[1],
"BEGIN_DATE": parseDate,
"END_DATE":parseDateB,
"IPHASE":rowData[4] }
}
this.uploadExcel(newData);//failing unable to call uploadExcel method or function
}
};
},
thanks
Vijay
Hi bl vijaykumar,
You wont be able to access "this" in the reader.onload, you can do it in the below two ways
1. use jQuery.proxy
reader.onloadend = jQuery.proxy(function () {
// your code
}, this);
2. use bind(this)
reader.onloadend = function () {
// your code
}.bind(this);
3. pass the "this" reference to some variable
var that = this;
reader.onloadend = function(e){
that.yourMethod();
};
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay Kumar,
Yes, this scope is not available inside the File reader onload method. Sample code is available here.
Thanks,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.