<?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 JSAPI 4.x - Push query results to a FeatureForm? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-x-push-query-results-to-a-featureform/m-p/1179611#M77574</link>
    <description>&lt;P&gt;I haven't been able to find any examples of this or anything similar but I am wondering if it is possible to push query results to a feature form. What I need to have happen is when someone selects a species from a dropdown within the feature form it will populate 3 fields with information that is queried from a table (Genus, Species and USDA Plant Code). I have the query working and it returns the fields in the console but I don't quite know how to take those results and populate the feature form. Below is what I have now... also, I see that the "value-change" event for the feature form can be set on a specific field but there is no example of how that should look? In reality, I would only like this to occur when the "COMMON" field dropdown is modified.&lt;/P&gt;&lt;P&gt;I am using this example (&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Code Updated (6/10/22)&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have below is currently not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Highlights the clicked feature and display
        // the feature form with the incident's attributes.
        function selectFeature(objectId) {
          // query feature from the server
          obsLayer.queryFeatures({
              objectIds: [objectId],
              outFields: ["*"],
              returnGeometry: true
            }).then((results) =&amp;gt; {
              if (results.features.length &amp;gt; 0) {
                editFeature = results.features[0];

                // display the attributes of selected feature in the form
                featureForm.feature = editFeature;
                console.log("populate form");

                //**testing**
                //this query is performed when the selection changes on anything.
                //Returns the correct information
                featureForm.on("value-change", () =&amp;gt; {
                  var featureAtt = featureForm.getValues();
                  var attributesSpecies = Object.entries(featureAtt).map(([key, value]) =&amp;gt; ({key,value}));
                  var speciesID = attributesSpecies[9].value;
                  var speciesQuery = speciesTable.createQuery();
                  //speciesQuery.objectIds = [objectId];
                  speciesQuery.outfields = ["*"];
                  speciesQuery.returnGeometry = false;
                  speciesQuery.returnDistinctValues = true;
                  speciesQuery.where = "ID = " + speciesID + "";
                  //console.log(speciesQuery);
                  speciesTable.queryFeatures(speciesQuery).then(function(results){
                    var attributeArray = new Array();
                    results.features.forEach(function(item) {
                      attributeArray.push(item.attributes);
                    });
                    //console.log(attributeArray[0].GENUS);
                    var attr = [];
                    attr["GENUS"] = attributeArray[0].GENUS;
                    attr["SPECIES"] = attributeArray[0].SPECIES;
                    attr["PLANTCODE"] = attributeArray[0].PCODE;
                    console.log(attr);
                    editFeature.attributes.GENUS = attributeArray[0].GENUS,
                    editFeature.attributes.SPECIES = attributeArray[0].SPECIES,
                    editFeature.attributes.PLANTCODE = attributeArray[0].PCODE
                  })
                });
                //**end testing**

                // highlight the feature on the view
                view.whenLayerView(editFeature.layer).then((layerView) =&amp;gt; {
                  highlight = layerView.highlight(editFeature);
                });
              }
              console.log(editFeature);
            });
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jun 2022 12:56:26 GMT</pubDate>
    <dc:creator>luckachi</dc:creator>
    <dc:date>2022-06-10T12:56:26Z</dc:date>
    <item>
      <title>JSAPI 4.x - Push query results to a FeatureForm?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-x-push-query-results-to-a-featureform/m-p/1179611#M77574</link>
      <description>&lt;P&gt;I haven't been able to find any examples of this or anything similar but I am wondering if it is possible to push query results to a feature form. What I need to have happen is when someone selects a species from a dropdown within the feature form it will populate 3 fields with information that is queried from a table (Genus, Species and USDA Plant Code). I have the query working and it returns the fields in the console but I don't quite know how to take those results and populate the feature form. Below is what I have now... also, I see that the "value-change" event for the feature form can be set on a specific field but there is no example of how that should look? In reality, I would only like this to occur when the "COMMON" field dropdown is modified.&lt;/P&gt;&lt;P&gt;I am using this example (&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Code Updated (6/10/22)&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have below is currently not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Highlights the clicked feature and display
        // the feature form with the incident's attributes.
        function selectFeature(objectId) {
          // query feature from the server
          obsLayer.queryFeatures({
              objectIds: [objectId],
              outFields: ["*"],
              returnGeometry: true
            }).then((results) =&amp;gt; {
              if (results.features.length &amp;gt; 0) {
                editFeature = results.features[0];

                // display the attributes of selected feature in the form
                featureForm.feature = editFeature;
                console.log("populate form");

                //**testing**
                //this query is performed when the selection changes on anything.
                //Returns the correct information
                featureForm.on("value-change", () =&amp;gt; {
                  var featureAtt = featureForm.getValues();
                  var attributesSpecies = Object.entries(featureAtt).map(([key, value]) =&amp;gt; ({key,value}));
                  var speciesID = attributesSpecies[9].value;
                  var speciesQuery = speciesTable.createQuery();
                  //speciesQuery.objectIds = [objectId];
                  speciesQuery.outfields = ["*"];
                  speciesQuery.returnGeometry = false;
                  speciesQuery.returnDistinctValues = true;
                  speciesQuery.where = "ID = " + speciesID + "";
                  //console.log(speciesQuery);
                  speciesTable.queryFeatures(speciesQuery).then(function(results){
                    var attributeArray = new Array();
                    results.features.forEach(function(item) {
                      attributeArray.push(item.attributes);
                    });
                    //console.log(attributeArray[0].GENUS);
                    var attr = [];
                    attr["GENUS"] = attributeArray[0].GENUS;
                    attr["SPECIES"] = attributeArray[0].SPECIES;
                    attr["PLANTCODE"] = attributeArray[0].PCODE;
                    console.log(attr);
                    editFeature.attributes.GENUS = attributeArray[0].GENUS,
                    editFeature.attributes.SPECIES = attributeArray[0].SPECIES,
                    editFeature.attributes.PLANTCODE = attributeArray[0].PCODE
                  })
                });
                //**end testing**

                // highlight the feature on the view
                view.whenLayerView(editFeature.layer).then((layerView) =&amp;gt; {
                  highlight = layerView.highlight(editFeature);
                });
              }
              console.log(editFeature);
            });
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2022 12:56:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-x-push-query-results-to-a-featureform/m-p/1179611#M77574</guid>
      <dc:creator>luckachi</dc:creator>
      <dc:date>2022-06-10T12:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSAPI 4.x - Push query results to a FeatureForm?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-x-push-query-results-to-a-featureform/m-p/1182407#M77661</link>
      <description>&lt;P&gt;In case anyone else is trying to do something similar,&lt;/P&gt;&lt;P&gt;I solved this by replacing this in my original code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;editFeature.attributes.GENUS = attributeArray[0].GENUS,
editFeature.attributes.SPECIES = attributeArray[0].SPECIES,
editFeature.attributes.PLANTCODE = attributeArray[0].PCODE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;featureForm.viewModel.setValue("GENUS", attributeArray[0].GENUS);
featureForm.viewModel.setValue("SPECIES", attributeArray[0].SPECIES);
featureForm.viewModel.setValue("PLANTCODE", attributeArray[0].PCODE);&lt;/LI-CODE&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>Mon, 13 Jun 2022 18:08:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/jsapi-4-x-push-query-results-to-a-featureform/m-p/1182407#M77661</guid>
      <dc:creator>luckachi</dc:creator>
      <dc:date>2022-06-13T18:08:25Z</dc:date>
    </item>
  </channel>
</rss>

