<?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 Updating the results of a Query Statistic using Attribute Inspector in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349979#M32403</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My web app&amp;nbsp;allow users to edit existing polygon features using the attribute inspector. I have been trying to use a query to create a summary statistics to report back the&amp;nbsp;count of a specific attribute name. The app currently display the count of a specific feature but it&amp;nbsp;does not automatically update when a change is made to the feature using the attribute inspector. How can I get the query to automatically update the statistics after each change in the attribute.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is part of my code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; var blocks = new FeatureLayer("http://gis.dekalb.k12.ga.us/arcgis_webadapter/rest/services/Redistricting/ES_Areas_Redist_Test/FeatureServer/0", {
 mode: FeatureLayer.MODE_SNAPSHOT,
 outFields: ["ES_Name", "ES_City", "DDP_ES_Name"]
 });

 var selectionSymbol = new SimpleFillSymbol().setColor(new Color([255, 255, 255, 0.5]));
 blocks.setSelectionSymbol(selectionSymbol);

 blocks.setRenderer(renderer);
 map.addLayers([blocks]);

 map.on("layers-add-result", initSelectToolbar);

 //Code to store names for the query click
 map.infoWindow.on('show', function(evt) {
 setTimeout(function() {
 var node = dojoQuery('.atiField', evt.domNode);
 if (!node) {
 return;
 }
 var selectWid = registry.getEnclosingWidget(node[1]);
 //console.info(selectWid.get("store"));
 var oNames = [];
 array.map(uNames, function(fName) {
 oNames.push({
 id: fName,
 name: fName
 });
 });
 var data = {
 label: 'name',
 items: oNames
 };
 var store = new Memory({
 data: data
 });
 selectWid.setAttribute("store", store);
 }, 800);
 });


 function initSelectToolbar(evt) {
 var blocks = evt.layers[0].layer;
 var selectQuery = new Query();

 map.on("click", function(evt) {
 map.infoWindow.hide();
 selectQuery.outFields = ["*"];
 selectQuery.geometry = evt.mapPoint;
 selectQuery.returnGeometry = true;
 blocks.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function(features) {
 uNames = [];
 if (features.length &amp;gt; 0) {
 var attrQuery = new Query();
 attrQuery.geometry = features[0].geometry;
 attrQuery.outFields = ["ES_Name"];
 attrQuery.returnGeometry = false;
 attrQuery.spatialRelationship = Query.SPATIAL_REL_TOUCHES;
 blocks.queryFeatures(attrQuery, function(fset) {
 array.map(fset.features, function(feat) {
 var fname = feat.attributes.ES_Name;
 if (uNames.indexOf(fname) === -1) {
 uNames.push(fname);
 }
 });
 });
 //store the current feature
 updateFeature = features[0];
 title = "Study Area is " + features[0].attributes.DDP_ES_Name //InfoWindow Title with Attribute Name
 map.infoWindow.setTitle(title);
 map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
 } else {
 map.infoWindow.hide();
 }
 });
 });

 map.infoWindow.on("hide", function() {
 blocks.clearSelection();
 });

 var layerInfos = [{
 'featureLayer': blocks,
 'showAttachments': false,
 'isEditable': true,
 'fieldInfos': [{
 'fieldName': 'ES_City',
 'isEditable': false,
 'label': 'Current School:'
 }, {
 'fieldName': 'ES_Name',
 'isEditable': true,
 'label': 'Proposed School:'
 }]
 }];

 //Initialize Attribute Inspector
 var attInspector = new AttributeInspector({
 layerInfos: layerInfos
 }, domConstruct.create("div"));

 //add an apply button for any changes
 var saveButton = new Button({
 label: "Apply",
 "class": "saveButton"
 }, domConstruct.create("div"));
 domConstruct.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");

 saveButton.on("click", function() {
 updateFeature.getLayer().applyEdits(null, [updateFeature], null, function(result) {
 console.log(result);
 }, function(error) {
 console.log(error);
 });
 map.infoWindow.hide();
 blocks.clearSelection(selectionSymbol);
 });

 attInspector.on("attribute-change", function(evt) {
 //store the updates to apply when the save button is clicked
 updateFeature.attributes[evt.fieldName] = evt.fieldValue;
 });

 map.infoWindow.setContent(attInspector.domNode);
 map.infoWindow.resize(350, 240);
 }

&lt;STRONG&gt; map.on("update-end", function() {&lt;/STRONG&gt;

&lt;STRONG&gt; var sqlExpression = "ES_Name";&lt;/STRONG&gt;

&lt;STRONG&gt; // Object used to request the count of all block groups&lt;/STRONG&gt;

&lt;STRONG&gt; var countStatDef = new StatisticDefinition();&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.statisticType = "count";&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.onStatisticField = sqlExpression;&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.outStatisticFieldName = "numBlockGroups";&lt;/STRONG&gt;

&lt;STRONG&gt; var queryParams = new Query();&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.where = "ES_Name = 'North'";&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.outFields = ["*"];&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.returnGeometry = true;&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.outStatistics = [countStatDef];&lt;/STRONG&gt;
&lt;STRONG&gt; blocks.queryFeatures(queryParams, showResults);&lt;/STRONG&gt;

&lt;STRONG&gt; function showResults(results) {&lt;/STRONG&gt;
&lt;STRONG&gt; // The return object of the query containing the statistics requested&lt;/STRONG&gt;
&lt;STRONG&gt; var stats = results.features[0].attributes&lt;/STRONG&gt;

&lt;STRONG&gt; dom.byId("countResult").innerHTML = Math.round(stats.numBlockGroups);&lt;/STRONG&gt;
&lt;STRONG&gt; }&lt;/STRONG&gt;
&lt;STRONG&gt; })&lt;/STRONG&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:27:28 GMT</pubDate>
    <dc:creator>GiovanniMarrero3</dc:creator>
    <dc:date>2021-12-11T16:27:28Z</dc:date>
    <item>
      <title>Updating the results of a Query Statistic using Attribute Inspector</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349979#M32403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My web app&amp;nbsp;allow users to edit existing polygon features using the attribute inspector. I have been trying to use a query to create a summary statistics to report back the&amp;nbsp;count of a specific attribute name. The app currently display the count of a specific feature but it&amp;nbsp;does not automatically update when a change is made to the feature using the attribute inspector. How can I get the query to automatically update the statistics after each change in the attribute.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is part of my code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; var blocks = new FeatureLayer("http://gis.dekalb.k12.ga.us/arcgis_webadapter/rest/services/Redistricting/ES_Areas_Redist_Test/FeatureServer/0", {
 mode: FeatureLayer.MODE_SNAPSHOT,
 outFields: ["ES_Name", "ES_City", "DDP_ES_Name"]
 });

 var selectionSymbol = new SimpleFillSymbol().setColor(new Color([255, 255, 255, 0.5]));
 blocks.setSelectionSymbol(selectionSymbol);

 blocks.setRenderer(renderer);
 map.addLayers([blocks]);

 map.on("layers-add-result", initSelectToolbar);

 //Code to store names for the query click
 map.infoWindow.on('show', function(evt) {
 setTimeout(function() {
 var node = dojoQuery('.atiField', evt.domNode);
 if (!node) {
 return;
 }
 var selectWid = registry.getEnclosingWidget(node[1]);
 //console.info(selectWid.get("store"));
 var oNames = [];
 array.map(uNames, function(fName) {
 oNames.push({
 id: fName,
 name: fName
 });
 });
 var data = {
 label: 'name',
 items: oNames
 };
 var store = new Memory({
 data: data
 });
 selectWid.setAttribute("store", store);
 }, 800);
 });


 function initSelectToolbar(evt) {
 var blocks = evt.layers[0].layer;
 var selectQuery = new Query();

 map.on("click", function(evt) {
 map.infoWindow.hide();
 selectQuery.outFields = ["*"];
 selectQuery.geometry = evt.mapPoint;
 selectQuery.returnGeometry = true;
 blocks.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function(features) {
 uNames = [];
 if (features.length &amp;gt; 0) {
 var attrQuery = new Query();
 attrQuery.geometry = features[0].geometry;
 attrQuery.outFields = ["ES_Name"];
 attrQuery.returnGeometry = false;
 attrQuery.spatialRelationship = Query.SPATIAL_REL_TOUCHES;
 blocks.queryFeatures(attrQuery, function(fset) {
 array.map(fset.features, function(feat) {
 var fname = feat.attributes.ES_Name;
 if (uNames.indexOf(fname) === -1) {
 uNames.push(fname);
 }
 });
 });
 //store the current feature
 updateFeature = features[0];
 title = "Study Area is " + features[0].attributes.DDP_ES_Name //InfoWindow Title with Attribute Name
 map.infoWindow.setTitle(title);
 map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
 } else {
 map.infoWindow.hide();
 }
 });
 });

 map.infoWindow.on("hide", function() {
 blocks.clearSelection();
 });

 var layerInfos = [{
 'featureLayer': blocks,
 'showAttachments': false,
 'isEditable': true,
 'fieldInfos': [{
 'fieldName': 'ES_City',
 'isEditable': false,
 'label': 'Current School:'
 }, {
 'fieldName': 'ES_Name',
 'isEditable': true,
 'label': 'Proposed School:'
 }]
 }];

 //Initialize Attribute Inspector
 var attInspector = new AttributeInspector({
 layerInfos: layerInfos
 }, domConstruct.create("div"));

 //add an apply button for any changes
 var saveButton = new Button({
 label: "Apply",
 "class": "saveButton"
 }, domConstruct.create("div"));
 domConstruct.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");

 saveButton.on("click", function() {
 updateFeature.getLayer().applyEdits(null, [updateFeature], null, function(result) {
 console.log(result);
 }, function(error) {
 console.log(error);
 });
 map.infoWindow.hide();
 blocks.clearSelection(selectionSymbol);
 });

 attInspector.on("attribute-change", function(evt) {
 //store the updates to apply when the save button is clicked
 updateFeature.attributes[evt.fieldName] = evt.fieldValue;
 });

 map.infoWindow.setContent(attInspector.domNode);
 map.infoWindow.resize(350, 240);
 }

&lt;STRONG&gt; map.on("update-end", function() {&lt;/STRONG&gt;

&lt;STRONG&gt; var sqlExpression = "ES_Name";&lt;/STRONG&gt;

&lt;STRONG&gt; // Object used to request the count of all block groups&lt;/STRONG&gt;

&lt;STRONG&gt; var countStatDef = new StatisticDefinition();&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.statisticType = "count";&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.onStatisticField = sqlExpression;&lt;/STRONG&gt;
&lt;STRONG&gt; countStatDef.outStatisticFieldName = "numBlockGroups";&lt;/STRONG&gt;

&lt;STRONG&gt; var queryParams = new Query();&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.where = "ES_Name = 'North'";&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.outFields = ["*"];&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.returnGeometry = true;&lt;/STRONG&gt;
&lt;STRONG&gt; queryParams.outStatistics = [countStatDef];&lt;/STRONG&gt;
&lt;STRONG&gt; blocks.queryFeatures(queryParams, showResults);&lt;/STRONG&gt;

&lt;STRONG&gt; function showResults(results) {&lt;/STRONG&gt;
&lt;STRONG&gt; // The return object of the query containing the statistics requested&lt;/STRONG&gt;
&lt;STRONG&gt; var stats = results.features[0].attributes&lt;/STRONG&gt;

&lt;STRONG&gt; dom.byId("countResult").innerHTML = Math.round(stats.numBlockGroups);&lt;/STRONG&gt;
&lt;STRONG&gt; }&lt;/STRONG&gt;
&lt;STRONG&gt; })&lt;/STRONG&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:27:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349979#M32403</guid>
      <dc:creator>GiovanniMarrero3</dc:creator>
      <dc:date>2021-12-11T16:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Updating the results of a Query Statistic using Attribute Inspector</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349980#M32404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would run the query each time the attributes get updated (in the "attribute-change" event handler)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 20:58:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349980#M32404</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2018-04-03T20:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Updating the results of a Query Statistic using Attribute Inspector</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349981#M32405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply. I tried using that method. The info populates as it should once the attribute changes but it does not update the total count, stays the same regardless of the changes.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Apr 2018 15:07:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349981#M32405</guid>
      <dc:creator>GiovanniMarrero3</dc:creator>
      <dc:date>2018-04-04T15:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Updating the results of a Query Statistic using Attribute Inspector</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349982#M32406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update.. the original script was working correctly. I had to change my layer privileges to update so that the query would recognize the new updated attributes. I did not realize that the query function is called back to the server, i though it could query on the client-side.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to query on the client side instead back to the server so that I can reset the layer back to select only?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2018 13:31:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/updating-the-results-of-a-query-statistic-using/m-p/349982#M32406</guid>
      <dc:creator>GiovanniMarrero3</dc:creator>
      <dc:date>2018-04-13T13:31:41Z</dc:date>
    </item>
  </channel>
</rss>

