Posted 18 May 2018, 3:56 am EST
To elaborate a bit…
This is an Angular 2+ application.
I have a webpage which has the following:
-
A form with some fields e.g. DateFrom, DateTo, SiteId
-
A class level function e.g. GetCapacityFromDB(dateFrom, DateTo, SiteId) which makes HTTP request to fetch data from backend using the value of the form fields as parameters and returns a integer. Capacity value for the Site for the date range
-
An empty FlexSheet
I am trying to add a CustomFunction in the flexsheet called GetCapacity() with no parameters.
My objective is that the user will type in =GetCapacity in the FlexSheet cell.
It will then call class level function and return the integer as explained in point #2 above.
The problem I am facing is that:
A. I am being able to access class level function GetCapacityFromDB while declaring, but at run time none of the class level members are getting available.
B. Since the HTTP request is asynchronous, how do I wait for the value from DB to return, before I return the value for the CustomFunction call.
Refer to the below code snippet:
this.flxSheet = new FlexSheet("#excel");
this.flxSheet.addUnboundSheet("Report Template",500,500,0);
this.flxSheet.addFunction("GetCapacity",this.GetCapacityFromDB,"Returns Installed Capacity of the Site",0,0);
GetCapacityFromDB(dateFrom, DateTo, SiteId){
const that = this;
let param: QueryParam= new QueryParam();
let result=0;
param.FieldId = SiteId;
param.StartDate = dateFrom;
param.EndDate =DateTo;
that.reportService.GetFieldData(param).subscribe(data=>{
console.log(data);
result= data.length;
});
return result
}