Select to view content in your preferred language

data expression failed to fetch error

86
2
Jump to solution
Tuesday
RobertMateja
New Contributor II

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));

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Can you try to put return fs right after your FeatureSetByPortalItem function? If your expression isn't even connecting to the data source, the rest of the expression doesn't matter.

Looking at your expression, you'll need to adjust your DaysToClose expression near the end. You're not listing your parameters correctly. If your expression gets down to that line once your initial problem is fixed, it will give you another error.

'DaysToClose': DateDiff(EndDate, StartDate, 'days')

Also, I'm not sure what you're attempting when you create the variables StartDate and EndDate. Calling the Date function against an entire featureset won't give you anything. You need to somehow specify an individual feature to pull the date from. Perhaps the start and end dates are meant to be in the for loop?

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Can you try to put return fs right after your FeatureSetByPortalItem function? If your expression isn't even connecting to the data source, the rest of the expression doesn't matter.

Looking at your expression, you'll need to adjust your DaysToClose expression near the end. You're not listing your parameters correctly. If your expression gets down to that line once your initial problem is fixed, it will give you another error.

'DaysToClose': DateDiff(EndDate, StartDate, 'days')

Also, I'm not sure what you're attempting when you create the variables StartDate and EndDate. Calling the Date function against an entire featureset won't give you anything. You need to somehow specify an individual feature to pull the date from. Perhaps the start and end dates are meant to be in the for loop?

- Josh Carlson
Kendall County GIS
0 Kudos
RobertMateja
New Contributor II

Josh,

I put the return fs right after the FeatureSetByPortalItem function as you suggested and no data is returned.  I guess I need to figure that out.  If I change the portalitem to a different feature layer it works without issue.  I guess I will need to figure out what is going on with this specific feature layer.  Thanks for the help.  I  am sure I will be back once I get this issue resolved.

rob

 

 

0 Kudos