<?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 update / add feature attributes? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232945#M79375</link>
    <description>&lt;P&gt;Yes, they exist, the features all contain v1 -&amp;gt; v4, v1 is always a number from 0 - 100 in string form, and I'm doing feature.setAttribute('v1', "SUPERRANDOMSET").&amp;nbsp; After that logic runs v1 is still "0" - "100", when I expect it to be "SUPERRANDOMSET".&lt;BR /&gt;&lt;BR /&gt;Could there be a problem running the update on a layer that was created from ArcGIS Online? I've been able to do this with client side graphics when I build them manually.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 20:53:53 GMT</pubDate>
    <dc:creator>AndrewMurdoch1</dc:creator>
    <dc:date>2022-11-17T20:53:53Z</dc:date>
    <item>
      <title>How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232469#M79347</link>
      <description>&lt;P&gt;Good Day&lt;BR /&gt;&lt;BR /&gt;I already know about setAttribute, my question is how save the update so my attribute become available?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.grabData().then(() =&amp;gt; {
	this.queryAllFeatures(this._layers[0]).then((features: Graphic[]) =&amp;gt; {
  		features.forEach((feature, idx) =&amp;gt; {
    			const matchedFeature = this.data.find(d =&amp;gt; d.x === feature.attributes.x)
	
    			if (matchedFeature) {
			      const value1 =
				matchedFeature?.box?.find(i =&amp;gt; i.type === 'a').value ?? 0;

				feature.setAttribute('someValue', Number(value1));
				// Repeated X times
    			}
  		})
  	})
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If I do this, and try to reference "someValue" I get an error that it doesn't exist, so I tried to use "applyEdits" to update the value:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;this._layers[0].applyEdits({ updateFeatures: features })
    .then((editsResult) =&amp;gt; {
        console.log('Edit Results');
        console.log(editsResult);
    })
    .catch((error) =&amp;gt; {
        console.log("error = ", error);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Which works, but I still don't see my new attributes.&amp;nbsp; Previous I was getting an error from applyEdits, but I resolved that problem!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Can anyone see what I'm doing wrong?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 22:00:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232469#M79347</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2022-11-16T22:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232793#M79362</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;It is hard to suggest anything without a repro case. Are you working with a FeatureLayer that references a feature service or is this a client-side FeatureLayer? You should see the updated values for feature services without having to do anything as long as applyEdits resolves successfully. For client-side featureLayer, you have to query the updated features once applyEdits resolves successfully.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is explained in this document: &lt;A href="https://next.sites.afd.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#applyEdits" target="_blank"&gt;https://next.sites.afd.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#applyEdits&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This very simple sample shows and explains this workflow:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 17:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232793#M79362</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-11-17T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232837#M79367</link>
      <description>&lt;P&gt;Good Day&lt;BR /&gt;&lt;BR /&gt;Thanks for the reply, I'm using a Hosted Feature Layer, please see this more complete example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;addGISFeatureAttributes(layer: FeatureLayer) {
    return new Promise((r) =&amp;gt; {
      console.time('correlationLook10k');
      this.queryAllFeatures(layer).then((features: Graphic[]) =&amp;gt; {
        this.grabData().then(() =&amp;gt; {
          features.forEach((feature, idx) =&amp;gt; {
            const matchedFeature =
              this.data.find(d =&amp;gt; d.x === feature.attributes.x)

            if (matchedFeature) {
              const value1 =
                matchedFeature?.find(m =&amp;gt; m.type === 'v1').value ?? 0;

              const value2 =
                matchedFeature?.find(m =&amp;gt; m.type === 'v1').value ?? 0;
                
              const value3 =
                matchedFeature?.find(m =&amp;gt; m.type === 'v1').value ?? 0;
                
              feature.setAttribute('v1', Number(value1));
              feature.setAttribute('v2', Number(value2));
              feature.setAttribute('v3', Number(value3));
              feature.attributes.v4 = Number(value3);
            }
          })

          layer.applyEdits({updateFeatures: features}).then((updateResults) =&amp;gt; {
            console.log('Update Results');
            console.log(updateResults);

            const query = {
              where: '1=1',
              outFields:['*'],
              returnGeometry: true,
              maxRecordCountFactor: 5
            }

            const objectIds = [];
            updateResults.updateFeatureResults.forEach((item) =&amp;gt; {
              objectIds.push(item.objectId);
            });

            console.log('Object Ids');
            console.log(objectIds);

            layer.queryFeatures(query).then((results) =&amp;gt; {
              console.log(results.features.length, "features have been added.");
              console.timeEnd('correlationLook10k');
              r(results);
            }).catch((error) =&amp;gt; {
              console.log('Query Feature Error');
              console.log(error);
            })
          }).catch((error) =&amp;gt; {
            console.log('Upload Error');
            console.log(error);
          })
        });
      });
    });
  }

  showPortalFeatureLayerByYear(year: number = new Date().getFullYear()) {
    let layerId = "SOME PORTAL ID"

    this._layers = [];
    new FeatureLayer({
      portalItem: {
        id: layerId,
      },
      outFields: ['*']
    }).load().then((layer) =&amp;gt; {
      this.addGISFeatureAttributes(layer).then((features: FeatureSet) =&amp;gt; {

        console.log('Features');
        console.log(_.cloneDeep(features));

        return new FeatureLayer({
          source: features.features,
          fields: features.fields,
          renderer: null,
          spatialReference: {
            wkid: 102100
          },
          outFields: ["*"]
        }).load().then((layer) =&amp;gt; {
          this._layers.push(layer);
          this.renderHostedFeatureLayer();
        })
      })
    })
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should I have my new layer with v1 -&amp;gt; v4?&amp;nbsp; This does the applyEdits, and this does the query stage.&amp;nbsp; One thing I've noticed, this is slow, ~60 seconds for 10k assets, so this generally not recommended?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 17:57:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232837#M79367</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2022-11-17T17:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232929#M79373</link>
      <description>&lt;P&gt;Can you verify that the fields you are trying to update are in the the layers &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#fields" target="_blank" rel="noopener"&gt;fields&lt;/A&gt; array?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 20:42:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232929#M79373</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-11-17T20:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232945#M79375</link>
      <description>&lt;P&gt;Yes, they exist, the features all contain v1 -&amp;gt; v4, v1 is always a number from 0 - 100 in string form, and I'm doing feature.setAttribute('v1', "SUPERRANDOMSET").&amp;nbsp; After that logic runs v1 is still "0" - "100", when I expect it to be "SUPERRANDOMSET".&lt;BR /&gt;&lt;BR /&gt;Could there be a problem running the update on a layer that was created from ArcGIS Online? I've been able to do this with client side graphics when I build them manually.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 20:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232945#M79375</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2022-11-17T20:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to update / add feature attributes?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232998#M79377</link>
      <description>&lt;P&gt;The other question I should ask, is this even recommended or practical to do?&amp;nbsp; We could have layers with 100k+ features in them, and we'd want to perform the same kind of step, is there anyway to do this at scale and with minimal latency?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 22:26:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-update-add-feature-attributes/m-p/1232998#M79377</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2022-11-17T22:26:39Z</dc:date>
    </item>
  </channel>
</rss>

