<?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: Obtaining unique Values based on user Input using Query() in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254912#M80157</link>
    <description>&lt;P&gt;Thank you, I fixed the issue by using predefined values&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2023 16:53:01 GMT</pubDate>
    <dc:creator>TheGamer</dc:creator>
    <dc:date>2023-02-03T16:53:01Z</dc:date>
    <item>
      <title>Obtaining unique Values based on user Input using Query()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254849#M80153</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi everyone Im having trouble getting the last element of the unique values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = FeatureLayer({
  url: "",
  });
const layer2 = FeatureLayer({
  url: "",
  refreshInterval:0.5
});
var id;
document.getElementById("animal").addEventListener("change", () =&amp;gt; {
   var arr=[];
   const query= layer.createQuery();
   query.where = "Animal= '" + document.getElementById("animal").value +"'";
   query.returnGeometry = false;
   query.returnDistinctValues = true;
   query.outFields=["ID", "Animal"];
   layer.queryFeatures(query).then(function(response){ 
       const values = response.features;
       if (values.length &amp;gt;0) {
           for (var i =0; i &amp;lt; values.length; i++) {
             arr[i] = values[i].attributes['ID'];
           }
           id= parseInt(arr.at(arr.length-1))+1
       }
       else {
           id= 1;
       }            
       });

 });
document.getElementById("createdata").onclick = () =&amp;gt; {
  const long = document.getElementById("LONG").value;
  const lat = document.getElementById("LAT").value;
  const point = {
        type: "point",
        longitude: long,
        latitude: lat,
  };
  const simpleMarkerSymbol = {
        type: "simple-marker",
        color: [226, 119, 40],
        outline: {
                 color: [12, 137, 148],
                 width: 0.5,
                 },
        };
                
        const pointGraphic = new Graphic({
              geometry: point,
              symbol: simpleMarkerSymbol,
              attributes: {
                    Name: document.getElementById("name").value,
                    Animal: document.getElementById("animal").value,
                    ID: id
                  },
                });
        layer2.applyEdits({ addFeatures: [pointGraphic] });
        document.getElementById("animal").value = "";
        document.getElementById("name").value = "";
};
&amp;lt;div class="esri-widget"&amp;gt;
   &amp;lt;input id="city" size="15" /&amp;gt;
&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm trying to generate new ids and add them to the feature layer. In order to do so I want to see if the animal inputted by the user exists in the data, if it does it should get the unique values, extract the last unique id (max id) and add 1 to it. But, if the animal doesn't exist in the data, it should assign id =1.&lt;/P&gt;&lt;P&gt;The id should then be assigned as an attribute to the graphic, which is then added to the layer2 by doing:&amp;nbsp;&lt;SPAN&gt;layer2&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;applyEdits&lt;/SPAN&gt;&lt;SPAN&gt;({ &lt;/SPAN&gt;&lt;SPAN&gt;addFeatures&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;SPAN&gt;pointGraphic&lt;/SPAN&gt;&lt;SPAN&gt;] }); (* layer2 is a feature layer view of layer*)&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The problem is it works but sometimes it duplicates the last stored id and adds it again. So, for instance, if the current max id is 72, and I add keep adding data, at some random point, the id repeats itself when i add new data. There are also times when I will randomly get 1 even if I have the animal is in the data.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6522"&gt;@JoelBennett&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/14934"&gt;@SageWall&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Feb 2023 15:12:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254849#M80153</guid>
      <dc:creator>TheGamer</dc:creator>
      <dc:date>2023-02-03T15:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining unique Values based on user Input using Query()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254871#M80154</link>
      <description>&lt;P&gt;Is the animal element a drop-down with predefined values? Or is a text input?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 15:41:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254871#M80154</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2023-02-03T15:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining unique Values based on user Input using Query()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254872#M80155</link>
      <description>&lt;P&gt;Hi, it's a text input&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 15:45:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254872#M80155</guid>
      <dc:creator>TheGamer</dc:creator>
      <dc:date>2023-02-03T15:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining unique Values based on user Input using Query()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254894#M80156</link>
      <description>&lt;P&gt;Probably that is the issue then. You are running the query every time user enters a character. Can you please change your logic so that you are running the query when user hits enter button in the input? Or add a button and run the query from the button's click event.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:26:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254894#M80156</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2023-02-03T16:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining unique Values based on user Input using Query()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254912#M80157</link>
      <description>&lt;P&gt;Thank you, I fixed the issue by using predefined values&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:53:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/obtaining-unique-values-based-on-user-input-using/m-p/1254912#M80157</guid>
      <dc:creator>TheGamer</dc:creator>
      <dc:date>2023-02-03T16:53:01Z</dc:date>
    </item>
  </channel>
</rss>

