<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcade Data Expression Not Creating FeatureSet in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586602#M10768</link>
    <description>&lt;P&gt;Hi Ken,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for responding. When I edited the code to your above suggestion, I got an invalid parameter error.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScreenshotParameterError.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/125692i8CB40BADFB9D07F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="ScreenshotParameterError.png" alt="ScreenshotParameterError.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2025 19:59:46 GMT</pubDate>
    <dc:creator>HaydenHarrison1</dc:creator>
    <dc:date>2025-02-18T19:59:46Z</dc:date>
    <item>
      <title>Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586562#M10766</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;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) &amp;amp;&amp;amp; !IsEmpty(endDate)) {
        // Calculate days to complete
        var daysToComplete = DateDiff(endDate, startDate, 'days');
 
        // Only include work orders that took more than 7 days
        if (daysToComplete &amp;gt; 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))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 19:16:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586562#M10766</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2025-02-18T19:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586572#M10767</link>
      <description>&lt;P&gt;You're building the array of filterFeatures, but you don't add that to finalTable.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var finaltable = {
  fields: [
    { name: "WorkOrderID", type: "esriFieldTypeString" },
    { name: "InitiateDate", type: "esriFieldTypeDate" },
    { name: "ActualFinishDate", type: "esriFieldTypeDate" },
    { name: "DaysToComplete", type: "esriFieldTypeInteger" }
  ],
  geometryType: "",
  features: filteredFeatures
};

return FeatureSet(finaltable);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Feb 2025 19:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586572#M10767</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-02-18T19:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586602#M10768</link>
      <description>&lt;P&gt;Hi Ken,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for responding. When I edited the code to your above suggestion, I got an invalid parameter error.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScreenshotParameterError.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/125692i8CB40BADFB9D07F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="ScreenshotParameterError.png" alt="ScreenshotParameterError.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 19:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586602#M10768</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2025-02-18T19:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586636#M10769</link>
      <description>&lt;P&gt;I ran your code using my own data and discovered that you have to convert daysToComplete to an integer (line 34). Otherwise, it ran correctly (with some field name changes and a different minimum days)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var workorders = Top(
  FeatureSetByPortalItem(
    Portal("https://noaa.maps.arcgis.com/"),
    "b6b9dd55450a4f64bcafb3cd6e005a5c",
    0,
    ["stormdate", "surveydate", "efscale", "OBJECTID"],
    true
  ),
  10
);

var filteredFeatures = [];

// Loop through work orders
for (var wo in workorders) {
  var startDate = wo["stormdate"];
  var endDate = wo["surveydate"];

  // Ensure both dates are not empty or null
  if (!IsEmpty(startDate) &amp;amp;&amp;amp; !IsEmpty(endDate)) {
    // Calculate days to complete
    var daysToComplete = DateDiff(endDate, startDate, "days");
    // Only include work orders that took more than 7 days
    if (daysToComplete &amp;gt; 2) {
      // Add the feature to the filtered list
      Push(
        filteredFeatures,
        {
          attributes:
            {
              WorkOrderID: Text(wo["efscale"]),
              InitiateDate: Date(startDate),
              ActualFinishDate: Date(endDate),
              DaysToComplete: Floor(daysToComplete)
            }
        }
      );
    }
  }
}

var finaltable = {
  fields: [
    {
      name: "WorkOrderID",
      alias: "Work Order ID",
      type: "esriFieldTypeString"
    },
    { name: "InitiateDate", alias: "Initiate Date", type: "esriFieldTypeDate" },
    {
      name: "ActualFinishDate",
      alias: "Actual Finish Date",
      type: "esriFieldTypeDate"
    },
    {
      name: "DaysToComplete",
      alias: "Days To Complete",
      type: "esriFieldTypeInteger"
    }
  ],
  geometryType: "",
  features: filteredFeatures
};

return FeatureSet(finaltable);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 21:01:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586636#M10769</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-02-18T21:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586686#M10770</link>
      <description>&lt;P&gt;Changing the daystoComplete worked! I can now see the featureset. However, the date fields aren't populating. Thoughts?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var workorders = FeatureSetByPortalItem(
    portal,
    'id',
    0,
    ['InitiateDate', 'ActualFinishDate', 'Priority', 'WorkOrderID', 'OBJECTID','DESCRIPTION'],
    false
);

// Debug: Check if workorders were retrieved
Console("Total Work Orders: " + Count(workorders));

var filteredFeatures = [];

// Loop through work orders
for (var wo in workorders) {
    var startDate = Date(wo["InitiateDate"]);
    var endDate = Date(wo["ActualFinishDate"]);

    // Debug: Log first work order details
    if (Count(filteredFeatures) == 0) {
        Console("Sample Work Order: " + Text(wo));
    }

    // Ensure both dates are valid
    if (!IsEmpty(startDate) &amp;amp;&amp;amp; !IsEmpty(endDate)) {
        // Calculate days to complete
        var daysToComplete = DateDiff(endDate, startDate, "days");

        // Only include work orders that took more than 7 days
        if (daysToComplete &amp;gt; 7) {
            // Add the feature to the filtered list
            Push(filteredFeatures, {
                attributes: {
                    WorkOrderID: Text(wo["WorkOrderID"]),  // Ensure it's string
                    InitiateDate: Date(startDate),
                    ActualFinishDate: Date(endDate),
                    DaysToComplete: Floor(daysToComplete),
                    OBJECTID: (wo["OBJECTID"]),
                    Description: (wo["DESCRIPTION"])
                }
            });
        }
    }
}

// Debug: Check how many were filtered
Console("Filtered Work Orders: " + Count(filteredFeatures));

return FeatureSet(Text({
    fields: [
        { name: "WorkOrderID", alias: "Work Order ID", type: "esriFieldTypeString" },
        { name: "startDate", alias: "Initiate Date", type: "esriFieldTypeDate" },
        { name: "endDate", alias: "Actual Finish Date", type: "esriFieldTypeDate" },
        { name: "daysToComplete", alias: "Days To Complete", type: "esriFieldTypeInteger" },
        { name: "Description", alias: "Description", type: "esriFieldTypeString" },
        { name: "OBJECTID", alias: "OBJECTID", type: "esriFieldTypeOID" },
    ],
    geometryType: "",
    features: filteredFeatures
}))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 22:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586686#M10770</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2025-02-18T22:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586917#M10773</link>
      <description>&lt;P&gt;The field names in the dictionary ("startDate" and "endDate") are different than the attributes in the array ("InitiateDate" and "ActualFinishDate")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 14:05:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586917#M10773</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-02-19T14:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586973#M10774</link>
      <description>&lt;P&gt;Unfortunately the feature set will not populate unless I use "startDate" and "endDate".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:06:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586973#M10774</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2025-02-19T15:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression Not Creating FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586982#M10776</link>
      <description>&lt;P&gt;What I mean is that the attribute keys have to be the same as the Dictionary field names to be mapped properly&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;attributes: {
  WorkOrderID: Text(wo["WorkOrderID"]),  // Ensure it's string
  InitiateDate: Date(startDate),
  ActualFinishDate: Date(endDate),
  DaysToComplete: Floor(daysToComplete),
  OBJECTID: (wo["OBJECTID"]),
  Description: (wo["DESCRIPTION"])
}
--------------------
fields: [
  { name: "WorkOrderID", alias: "Work Order ID", type: "esriFieldTypeString" },
  { name: "InitiateDate", alias: "Initiate Date", type: "esriFieldTypeDate" },
  { name: "ActualFinishDate", alias: "Actual Finish Date", type: "esriFieldTypeDate" },
  { name: "daysToComplete", alias: "Days To Complete", type: "esriFieldTypeInteger" },
  { name: "Description", alias: "Description", type: "esriFieldTypeString" },
  { name: "OBJECTID", alias: "OBJECTID", type: "esriFieldTypeOID" },
],&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:26:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-not-creating-featureset/m-p/1586982#M10776</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-02-19T15:26:11Z</dc:date>
    </item>
  </channel>
</rss>

