Hello,
I am trying to create a data expression that would query a feature layer containing work orders (WOs) and determine how many "outstanding" WOs (aka older than 7 days) we've had over the last 5 years. I am able to loop through the dataset and get a count of all outstanding work orders but can't get it to create a featureset to use in a chart widget on a dashboard. The output is a blank featureset. Version context: enterprise portal is on 11.1. Any input is greatly appreciated.
var workorders = FeatureSetByPortalItem(
portal,
'itemid',
0,
['InitiateDate', 'ActualFinishDate', 'Priority', 'WorkOrderID', 'OBJECTID'],
true
);
var filteredFeatures = [];
// Loop through work orders
for (var wo in workorders) {
var startDate = wo["InitiateDate"];
var endDate = wo["ActualFinishDate"];
// Ensure both dates are not empty or null
if (!IsEmpty(startDate) && !IsEmpty(endDate)) {
// Calculate days to complete
var daysToComplete = DateDiff(endDate, startDate, 'days');
// Only include work orders that took more than 7 days
if (daysToComplete > 7) {
// Add the feature to the filtered list
Push(filteredFeatures, {
attributes: {
WorkOrderID: Text(wo["WorkOrderID"]),
InitiateDate: Date(startDate),
ActualFinishDate: Date(endDate),
DaysToComplete: daysToComplete
}
});
}
}
}
var finaltable = {
fields: [
{name: 'WorkOrderID', type: 'esriFieldTypeString'},
{name: 'InitiateDate', type: 'esriFieldTypeDate'},
{name: 'ActualFinishDate', type: 'esriFieldTypeDate'},
{name: 'DaysToComplete', type: 'esriFieldTypeInteger'}
],
geometryType: '',
features: [
{attributes: {
WorkOrderID: Text(wo["WorkOrderID"]),
InitiateDate: (startDate),
ActualFinishDate: (endDate),
DaysToComplete: (daysToComplete)
}
}
]
}
return FeatureSet(Text(finaltable))