<?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: applyEdits not working in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017071#M71382</link>
    <description>&lt;P&gt;Thank you very much &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;, it works. One more question: once we update the attribute value, shouldn't the value in popup window update by itself? Also the value in featuretable widget (assuming we have it in this code)?&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jan 2021 21:25:15 GMT</pubDate>
    <dc:creator>RabinSubedi</dc:creator>
    <dc:date>2021-01-14T21:25:15Z</dc:date>
    <item>
      <title>applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016684#M71378</link>
      <description>&lt;P&gt;Hello Everyone!&lt;/P&gt;&lt;P&gt;I am trying to update the existing value of "PCR_NBR" in featurelayer by looking at the sample code of ArcGIS API for JS using apply edits, but its not working. In this code I am just trying to replace the value by 20. Also is it possible to run loop to have conditional statement, for eg: if PCR_NBR is less than 50, replace it by 20, if it is more than 50, replace it by 100?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;
      Update Feature Attributes | Sample | ArcGIS API for JavaScript 4.18
    &amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }

      #info {
        padding: 14px;
        border-radius: 5px;
      }

      #update {
        padding: 6px;
      }

      #form {
        background: #fff;
      }

      /* replaces esri-widget--panel */
      .scroller {
        overflow-x: hidden;
        overflow-y: auto;
      }

    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/FeatureForm",
        "esri/layers/FeatureLayer",
        "esri/form/FormTemplate"
      ], function(Map, MapView, FeatureForm, FeatureLayer, FormTemplate) {
        let highlight, editFeature;
        var popupMajorRoads = {
          title: "Pavement Condition Rating(PCR): " + "{PCR_NBR}",
          content: [{
            type: "fields",
            fieldInfos: [{
                fieldName: "PCR_YEAR",
                label: "PCR Year",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "PCR_NBR",
                label: "Pavement Condition (PCR)",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "NLFID",
                label: "NLFID",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "JURISDICTI",
                label: "Juristiction",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "ROUTE_TYPE",
                label: "Route Type",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "ROUTE_NBR",
                label: "Route Number",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "DIRECTION_",
                label: "Direction",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              },
              {
                fieldName: "LANES",
                label: "Number of Lanes",
                isEditable: true,
                tooltip: "",
                visible: true,
                format: null,
                stringFieldOption: "text-box"
              }
            ]
          }]
        };
        const featureLayer = new FeatureLayer({
          portalItem: {
            id: "8108b08e5ec643388380599f82e84b96"
          },
          outFields: ["*"],
          visible: true,
          popupTemplate: popupMajorRoads
        });

        const map = new Map({
          basemap: "topo-vector",
          layers: [featureLayer]
        });

        let view = new MapView({
          map: map,
          container: "viewDiv",
          center: [-82.9988, 39.9612],
          zoom: 10,

        });
        featureLayer.queryFeatures({
            outFields: ["*"],
            returnGeometry: true
          })
          .then(function(results) {
            if (results.features.length &amp;gt; 0) {
              editFeature = results.features[0];
              editFeature.attributes.PCR_NBR = 20;
            }
          });

        const edits = {
          updateFeatures: [editFeature]
        };
        featureLayer.applyEdits(edits);

      });

    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="info" class="esri-widget"&amp;gt;
    &amp;lt;/div&amp;gt;

  &amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 23:20:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016684#M71378</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-13T23:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016845#M71379</link>
      <description>&lt;P&gt;Starting with the simplest things, have you verified the PortalItem is hosted as a &lt;A href="https://developers.arcgis.com/rest/services-reference/feature-service.htm" target="_self"&gt;Feature Service&lt;/A&gt; with Update capabilities? Are you getting an error in the console?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 14:30:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016845#M71379</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-01-14T14:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016882#M71380</link>
      <description>&lt;P&gt;You are calling applyEdits outside the queryFeatures function, meaning it's trying to apply the edits before the query is finished. Try moving it inside the "then" function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;featureLayer.queryFeatures({
  outFields: ["*"],
  returnGeometry: true
})
  .then(function(results) {
    if (results.features.length &amp;gt; 0) {
    editFeature = results.features[0];
    editFeature.attributes.PCR_NBR = 20;
    const edits = {
      updateFeatures: [editFeature]
    };
    featureLayer.applyEdits(edits);
  }
});
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 15:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016882#M71380</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2021-01-14T15:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016897#M71381</link>
      <description>&lt;P&gt;As for doing it in a loop, try this (untested).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;editFeatures = results.features;
editFeatures.forEach(editFeature =&amp;gt; {
  if (editFeature.attributes.PCR_NBR &amp;lt; 50) {
    editFeature.attributes.PCR_NBR = 20;
  } else {
    editFeature.attributes.PCR_NBR = 100;
  }
});
const edits = {
  updateFeatures: editFeatures
};
featureLayer.applyEdits(edits);&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>Thu, 14 Jan 2021 16:01:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1016897#M71381</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2021-01-14T16:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017071#M71382</link>
      <description>&lt;P&gt;Thank you very much &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;, it works. One more question: once we update the attribute value, shouldn't the value in popup window update by itself? Also the value in featuretable widget (assuming we have it in this code)?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 21:25:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017071#M71382</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-14T21:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017072#M71383</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;Thanks for your reply. I am not sure if I understood your question properly or not. I just uploaded a shapefile to arcgis for developers and got portalid from there. I didn't add any additional settings to it. Also, I don't want this code to make changes to the original data in server, I just want to make temporary change on workspace only.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 21:29:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017072#M71383</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-14T21:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: applyEdits not working</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017074#M71384</link>
      <description>&lt;P&gt;No worries. Looks like you were able to get to the root of the problem. Carry on!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 21:33:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/applyedits-not-working/m-p/1017074#M71384</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-01-14T21:33:06Z</dc:date>
    </item>
  </channel>
</rss>

