I am trying to run some async code in function(1) but I am unable to get the output of the function(1), which I need to use as input for function(2). it returns 'undefined. however, if I put a breakpoint at the return statement of function(1) it starts working & stops again when I remove the breakpoint. I'd appreciate if anyone can help me with this.
oFile = oEvent.getParameter("files")[0];
var myFunc = function(){
return new Promise(function(resolve, reject) {
return resolve(S4HanaFioriAccelerator.common.handleListResponse(oFile));
});
};
myFunc().then(function success(data) {
console.log(data);
});
handleListResponse: function(file) {
var reader = new FileReader();
reader.onload = function(e) {
data = e.target.result;
results = [];
cfb = XLSX.read(data, {
type: 'binary'
});
cfb.SheetNames.forEach(function(sheetName) {
sCSV = XLS.utils.make_csv(cfb.Sheets[sheetName]);
oJS = XLS.utils.sheet_to_json(cfb.Sheets[sheetName]);
for(var i= 0; i < oJS.length; i++){
results.unshift(oJS[jsRowCount].Data);
}
console.log(results);
});
};
reader.readAsBinaryString(file);
setTimeout(function(){
console.log("Hello");
return results;
}, 3000);
}
output in console: undefined file1.js ["Student1", "Student2"] file2.js Hello file2.js
expected output: ["Student1", "Student2"] file2.js Hello file2.js ["Student1", "Student2"] file1.js