<?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: How to select the date of most recent record in featurelayer to automatically configure time slider in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474586#M84643</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;I gave your code a go and it was perfect in querying the earliest date in the dataset (which is at the top of the layer's table) but not the latest.&lt;/P&gt;&lt;P&gt;I gave finding the length of the feature layer a go and then putting that as the feature to be queried, however this just returned an error, which occurred whenever featureset.features[x] was over 999.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;   //Find the length of the entire feature layer
    layer.queryFeatureCount().then(function(numFeatures){
    // prints the total count to the console
    console.log(numFeatures); //49880

layer.queryFeatures().then((featureSet) =&amp;gt; {const endDateAttribute = featureSet.features[numFeatures].attributes.DATE_CREATED;
       
 
       // Create a Date object from the attribute value
       const enddate = new Date(endDateAttribute);
              console.log("enddate" , {enddate});
          
  //create time slider for layer 
  const timeSlider = new TimeSlider({
  container: "timeSlider",
  view: view,
  timeVisible: true, // show the time stamps on the timeslider
  loop: true,
  fullTimeExtent: { // entire extent of the timeSlider
    start: new Date(2003, 5, 18),
    end: enddate}
  });

  view.whenLayerView(layer).then((lv) =&amp;gt; {timeSlider.fullTimeExtent.expandTo("weeks");
  timeSlider.stops = {interval: layer.timeInfo.interval};
  });
  view.ui.add(timeSlider, "bottom-left"); 
});
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EmilyGoldsmith_0-1715957637295.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/104479iCAF6DBA929C544FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EmilyGoldsmith_0-1715957637295.png" alt="EmilyGoldsmith_0-1715957637295.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm a bit unsure of where to go from here. Do you think I have to set a 'wait until layer loaded' function prior to ensure the query can select the latest record?&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2024 15:03:48 GMT</pubDate>
    <dc:creator>EmilyGoldsmith</dc:creator>
    <dc:date>2024-05-17T15:03:48Z</dc:date>
    <item>
      <title>How to select the date of most recent record in featurelayer to automatically configure time slider</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474437#M84638</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm in a bit of an tricky situation where a layer with automatic refreshes in one of our ArcGIS JavaScript apps&amp;nbsp; has been configured to have an incorrect, static time extent in its timeinfo - with us being unable to make changes to said layer currently. This has led our time slider to have the wrong time extent info in our ArcGIS JavaScript 4.27 app.&lt;/P&gt;&lt;P&gt;A quick fix I came up with was to overwrite the time extent when setting up the timeslider, which has fixed the time extent issue temporarily - see here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//create time slider for layer 
        const timeSlider = new TimeSlider({
        container: "timeSlider",
        view: view,
        timeVisible: true, // show the time stamps on the timeslider
        loop: true,
        fullTimeExtent: { // entire extent of the timeSlider
          start: new Date(2003, 5, 19),
          end: new Date(2024, 5, 16)
  },
        });
      
        view.whenLayerView(layer).then((lv) =&amp;gt; {timeSlider.fullTimeExtent.expandTo("weeks");
        timeSlider.stops = {interval: layer.timeInfo.interval};
        });

        view.ui.add(timeSlider, "bottom-left");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to have a way to automatically get the most recent date from the feature layer's time field 'DATE_CREATED' and have this set to be the 'end' value in TimeSlider()'s 'fullTimeExtent.'&lt;/P&gt;&lt;P&gt;Does anybody know if this is possible?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 10:39:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474437#M84638</guid>
      <dc:creator>EmilyGoldsmith</dc:creator>
      <dc:date>2024-05-17T10:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the date of most recent record in featurelayer to automatically configure time slider</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474489#M84640</link>
      <description>&lt;P&gt;Assuming you referenced the layer and can query its features you can try something like this:&lt;/P&gt;&lt;P&gt;// Assuming your layer variable holds a reference to the layer&lt;BR /&gt;layer.queryFeatures().then((featureSet) =&amp;gt; {&lt;BR /&gt;const endDateAttribute = featureSet.features[0].attributes.DATE_CREATED;&lt;BR /&gt;&lt;BR /&gt;// Create a Date object from the attribute value&lt;BR /&gt;const endDate = new Date(endDateAttribute);&lt;BR /&gt;&lt;BR /&gt;// Create a time slider with the dynamic end date&lt;BR /&gt;const timeSlider = new TimeSlider({&lt;BR /&gt;container: "timeSlider", // ID of the HTML element where the time slider will be placed&lt;BR /&gt;view: view, // MapView or SceneView instance&lt;BR /&gt;timeVisible: true, // Show the time stamps on the time slider&lt;BR /&gt;loop: true, // Enable looping of time animation&lt;BR /&gt;fullTimeExtent: { // Entire extent of the time slider&lt;BR /&gt;start: new Date(2003, 5, 19), // Start date&lt;BR /&gt;end: endDate // End date based on the feature attribute&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// When the layer view is ready, configure the time slider&lt;BR /&gt;view.whenLayerView(layer).then((lv) =&amp;gt; {&lt;BR /&gt;timeSlider.fullTimeExtent.expandTo("weeks"); // Expand the time extent to weeks&lt;BR /&gt;timeSlider.stops = { interval: layer.timeInfo.interval }; // Set stops based on the layer's time interval&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Add the time slider to the view's UI (bottom-left position)&lt;BR /&gt;view.ui.add(timeSlider, "bottom-left");&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 12:43:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474489#M84640</guid>
      <dc:creator>AngelaSchirck</dc:creator>
      <dc:date>2024-05-17T12:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the date of most recent record in featurelayer to automatically configure time slider</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474586#M84643</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;I gave your code a go and it was perfect in querying the earliest date in the dataset (which is at the top of the layer's table) but not the latest.&lt;/P&gt;&lt;P&gt;I gave finding the length of the feature layer a go and then putting that as the feature to be queried, however this just returned an error, which occurred whenever featureset.features[x] was over 999.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;   //Find the length of the entire feature layer
    layer.queryFeatureCount().then(function(numFeatures){
    // prints the total count to the console
    console.log(numFeatures); //49880

layer.queryFeatures().then((featureSet) =&amp;gt; {const endDateAttribute = featureSet.features[numFeatures].attributes.DATE_CREATED;
       
 
       // Create a Date object from the attribute value
       const enddate = new Date(endDateAttribute);
              console.log("enddate" , {enddate});
          
  //create time slider for layer 
  const timeSlider = new TimeSlider({
  container: "timeSlider",
  view: view,
  timeVisible: true, // show the time stamps on the timeslider
  loop: true,
  fullTimeExtent: { // entire extent of the timeSlider
    start: new Date(2003, 5, 18),
    end: enddate}
  });

  view.whenLayerView(layer).then((lv) =&amp;gt; {timeSlider.fullTimeExtent.expandTo("weeks");
  timeSlider.stops = {interval: layer.timeInfo.interval};
  });
  view.ui.add(timeSlider, "bottom-left"); 
});
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EmilyGoldsmith_0-1715957637295.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/104479iCAF6DBA929C544FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EmilyGoldsmith_0-1715957637295.png" alt="EmilyGoldsmith_0-1715957637295.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm a bit unsure of where to go from here. Do you think I have to set a 'wait until layer loaded' function prior to ensure the query can select the latest record?&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 15:03:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1474586#M84643</guid>
      <dc:creator>EmilyGoldsmith</dc:creator>
      <dc:date>2024-05-17T15:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the date of most recent record in featurelayer to automatically configure time slider</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1475299#M84654</link>
      <description>&lt;P&gt;Hi, just to give an update on this but I think I figured out how to do it by adding a statistical query to your code.&lt;/P&gt;&lt;P&gt;Essentially, the following queries by the 'maximum' date in the FeatureLayer and then selects this date to be the timeslider's new 'enddate.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//Get the 'maximum' date (most recent)   
 const query = new Query();
    query.outStatistics = [{
  onStatisticField: "DATE_CREATED",
  outStatisticFieldName: "MAX_DATE",
  statisticType: "max"
  }];
  
//Query by the maxmimum date query set above
layer.queryFeatures(query).then((featureSet) =&amp;gt; {
  
  const endDateAttribute = featureSet.features[0].attributes.MAX_DATE;
  console.log("Most Recent Date", endDateAttribute); //Print this date

       // Create a Date object from the attribute value
       const enddate = new Date(endDateAttribute);
              console.log("enddate" , {enddate}); //Ensure date converted successfully
          
  //create time slider for layer 
  const timeSlider = new TimeSlider({
  container: "timeSlider",
  view: view,
  timeVisible: true, // show the time stamps on the timeslider
  loop: true,
  fullTimeExtent: { // entire extent of the timeSlider
    start: new Date(2003, 5, 19),
    end: enddate}
  });

  view.whenLayerView(layer).then((lv) =&amp;gt; {timeSlider.fullTimeExtent.expandTo("weeks");
  timeSlider.stops = {interval: layer.timeInfo.interval};
  });
  view.ui.add(timeSlider, "bottom-left"); 
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A solution to why the code in my previous message didn't work is because QueryTasks have a limit of 1000 (&lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/overcoming-querytask-limit-get-next-1000/td-p/707006" target="_self"&gt;see here&lt;/A&gt;.) Reading this post,&amp;nbsp; I was concerned I might have had to query by the maximum OBJECTID but this solution seems to work surprisingly well for now. Though I will keep an eye on it to ensure that it functions as it should.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 10:38:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1475299#M84654</guid>
      <dc:creator>EmilyGoldsmith</dc:creator>
      <dc:date>2024-05-20T10:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the date of most recent record in featurelayer to automatically configure time slider</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1475312#M84656</link>
      <description>&lt;P&gt;Great, glad you got it to work!&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 11:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-select-the-date-of-most-recent-record-in/m-p/1475312#M84656</guid>
      <dc:creator>AngelaSchirck</dc:creator>
      <dc:date>2024-05-20T11:35:55Z</dc:date>
    </item>
  </channel>
</rss>

