I have a javaScript method that returns a promise of reading data from an Excel sheet and return it in an array.
/* Get Column Data and return */
this.getColumnData = function(FileName,SheetName,ColumnName)
{
var ColumnDataList = new Array();
var workbook = new Excel.Workbook();
return workbook.xlsx.readFile(FileName).then(function() {
var worksheet = workbook.getWorksheet(SheetName);
for(var v=2;v<=worksheet.actualRowCount;v++)
{
ColumnDataList.push(worksheet.getCell(ColumnName+v).value);
}
return ColumnDataList;
});
};
Now while implementing the JS callback, I'm trying to assign the returned array in a variable and use it further, something like this:
var tmp = [];
it('Search TC#1 - ISBN ', function(){
xlReader.getColumnData('Test_Data.xlsx','Sheet1','A').then(function(dataList) {
tmp=dataList;
console.log('Inner Data : '+tmp);
});
console.log('Outer Data : '+tmp);
});
When I assign the returned value in a var tmp this tmp value can be accessed from inside the promise callback body but not from the outside. so the result that it prints is this:
Outer Data :
Inner Data : 9781405342704,9780241186091,9780241340189
As you can see that it returns nothing when called from outside of JS promise callback whereas I want to access the tmp variable data from the outside of promise callback body.