Good morning,
I am looking for a little help with setting up a data expression to use as the source of an indicator. I am looking to have the indicator return the number of days between 2 date fields (DateTimeInit and DateTimeClosed. I am also looking to have the expression pull in 2 other data fields from the feature layer, request id and description to set up other indicators such as average number of days to close for each type of request. Every time I test the expression I get the following error - Execution Error:Failed to fetch
This is the expression I have thus far;
//Pull in data from Closed Service Request feature layer
var portal = Portal('https:myurl');
var fs = FeatureSetByPortalItem(
portal,
'xx310x708a80409x960xx06e6xx0e8e6',
0,
['RequestId',
'Description',
'DateTimeInit',
'DateTimeClosed'
],
false
);
var StartDate = Date(fs,'DateTimeInit')
var EndDate = Date(fs,'DateTimeClosed')
//Create empty Dictionary
var fsDict = {
'fields': [
{'name': 'RequestId', 'type': 'esriFieldTypeString'},
{'name': 'Description', 'type': 'esriFieldTypeString'},
{'name': 'DateTimeInit', 'type': 'esriFieldTypeDate'},
{'name': 'DateTimeClosed', 'type': 'esriFieldTypeDate'},
{'name': 'DaysToClose', 'type': 'esriFieldTypeInteger'},
],
'geometryType': '',
'features':[]
};
var index = 0;
//Loop through features in the featureset to populate the dictionary
for (var feature in fs) {
fsDict.features[index++] = {
'attributes': {
'RequestId': feature['RequestId'],
'Description': feature['Description'],
'DateTimeInit': feature['DateTimeInit'],
'DateTimeClosed': feature['DateTimeClosed'],
'DaysToClose': DateDiff ([EndDate] -[StartDate], 'days')
}
}
}
//return dictionary
return FeatureSet(Text(fsDict));