<?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 updating feature service layer in Web AppBuilder Custom Widgets Questions</title>
    <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174742#M14752</link>
    <description>&lt;P&gt;If you're using the Edit toolbar, you can listen for the &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/edit-amd.html#event-graphic-move-stop" target="_self"&gt;graphic-move-stop&lt;/A&gt; event and save it then&lt;/P&gt;</description>
    <pubDate>Tue, 17 May 2022 18:53:39 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2022-05-17T18:53:39Z</dc:date>
    <item>
      <title>.applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174350#M14749</link>
      <description>&lt;P&gt;WAB Dev 2.19 / JavaScript 3.x&lt;/P&gt;&lt;P&gt;I have a custom widget with a button click that attaches to the reply_click() function below.&amp;nbsp; It successfully applies a query to select the feature (via attribute query), sets up a graphic to act as a highlight around the selected point feature and I can confirm the "selGraphic" that is created has the correct geometry and attributes.&lt;/P&gt;&lt;P&gt;What I am trying to implement is a way for the user to edit ("move" only) that selected graphic and then update the underlying&amp;nbsp;layer.layerObject.selectFeatures with the graphic that was "moved" by the user.&lt;/P&gt;&lt;P&gt;I'm not getting any errors and the&amp;nbsp;layer.layerObject.applyEdits() doesn't seem to choke or have any issues, however no edits are actually applied.&amp;nbsp; I've tried several variations of the applyEdits() method with similar results, all of these do nothing:&lt;/P&gt;&lt;P&gt;layer.layerObject.applyEdits(selGraphic, null, features[0])&lt;/P&gt;&lt;P&gt;layer.layerObject.applyEdits([selGraphic], null, features[0])&lt;/P&gt;&lt;P&gt;layer.layerObject.applyEdits([selGraphic], [], features[0])&lt;/P&gt;&lt;P&gt;layer.layerObject.applyEdits([selGraphic], null, [features[0]])&lt;/P&gt;&lt;P&gt;Any guidance is appreciated!&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;        reply_click: function (e) {  
            
            //console.log(e.target.id)
            this.map.itemInfo.itemData.operationalLayers.forEach(layer =&amp;gt; {
                if (layer.layerObject) {
                    if (layer.title === "Water Use Application Facilities") {                        
                        var queryTask = new QueryTask(layer.layerObject)
                        var query = new Query();
                        query.returnGeometry = true;
                        query.outFields = ['*']
                        query.where = "facilityId = '" + e.target.id + "'"                                           
                        
                        layer.layerObject.selectFeatures(query).then(function (features) {
                            if (layer.layerObject.geometryType === 'esriGeometryPoint' &amp;amp;&amp;amp; features.length === 1) {
                                
                                this.map.centerAt(features[0].geometry);
                                this.map.graphics.clear();
                                var selSymbolJson = {
                                    "color": [
                                        0,
                                        0,
                                        0,
                                        0
                                    ],
                                    "size": 30.5,
                                    "angle": 0,
                                    "xoffset": 0,
                                    "yoffset": 0,
                                    "type": "esriSMS",
                                    "style": "esriSMSCircle",
                                    "outline": {
                                        "color": [
                                            0,
                                            255,
                                            250,
                                            255
                                        ],
                                        "width": 2.50,
                                        "type": "esriSLS",
                                        "style": "esriSLSSolid"
                                    }
                                }
                                var attributes = {};
                                attributes['appId'] = features[0]['attributes'].appId //this.appId
                                attributes['facilityId'] = features[0]['attributes'].facilityId
                                attributes['facilityType'] = features[0]['attributes'].facilityType
                                attributes['facilityName'] = features[0]['attributes'].facilityName
                                attributes['permitId'] = features[0]['attributes'].permitId

                                var selGraphic = new Graphic(features[0].geometry, symbolJsonUtils.fromJson(selSymbolJson), attributes)
                                console.log(features[0].geometry)
                                map.graphics.clear();
                                map.graphics.add(selGraphic);
                                
                                this.editToolbar = new Edit(this.map, { allowAddVertices: false });
                                this.editToolbar.activate(Edit.MOVE, selGraphic);

                                this.map.on("click", function (evt) {
                                    layer.layerObject.applyEdits(selGraphic, null, features[0])                                    
                                    
                                    map.graphics.clear();
                                    map.graphics.add(selGraphic);
                                })                                
                            }
                        });
                    }
                }
            })
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 20:50:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174350#M14749</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-05-16T20:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174365#M14750</link>
      <description>&lt;P&gt;The last version ("[selGraphic], null, [features[0]]") should be the one that works, since applyEdits requires the parameters to be Graphics arrays. Are you keeping feature[0] so the user sees the original placement of it?&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 21:44:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174365#M14750</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-05-16T21:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174411#M14751</link>
      <description>&lt;P&gt;Ken -- thanks for the input.&lt;/P&gt;&lt;P&gt;I don't have the full workflow correct I'm sure.&amp;nbsp; The way I have it currently once the selection is applied the selected feature/graphic is moveable and the new location has the symbology of the graphic (all good so far).&amp;nbsp; Then when the user click elsewhere (not on the selected graphic), I want the applyEdits to immediately update the feature service with the new point location of the graphic and it's attributes (deleting the original point feature) and the underlying feature service to show the new point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I'm not sure that simply clicking off / on the map to applyEdits is the best idea.&amp;nbsp; I mean, that would get invoked anytime a click (identify feature for ex).&amp;nbsp; I think ideally, I just want to apply the edit immediately after the graphic has been moved.&lt;/P&gt;&lt;P&gt;Hope that makes sense but this is how I understood the various samples out there.&amp;nbsp; I'm all ears for guidance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 12:29:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174411#M14751</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-05-17T12:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174742#M14752</link>
      <description>&lt;P&gt;If you're using the Edit toolbar, you can listen for the &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/edit-amd.html#event-graphic-move-stop" target="_self"&gt;graphic-move-stop&lt;/A&gt; event and save it then&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 18:53:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174742#M14752</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-05-17T18:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174799#M14753</link>
      <description>&lt;P&gt;Great idea.&amp;nbsp; Thanks for that.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks like I'm close -- there is a new point feature created with all of the correct attributes, however the original point feature that I started with is not deleted.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        reply_click: function (e) {  

            console.log(e.target.id)
            this.map.itemInfo.itemData.operationalLayers.forEach(layer =&amp;gt; {
                if (layer.layerObject) {
                    if (layer.title === "Water Use Application Facilities") {                        
                        var queryTask = new QueryTask(layer.layerObject)
                        var query = new Query();
                        query.returnGeometry = true;
                        query.outFields = ['*']
                        query.where = "facilityId = '" + e.target.id + "'"                                           
                        
                        layer.layerObject.selectFeatures(query).then(function (features) {
                            if (layer.layerObject.geometryType === 'esriGeometryPoint' &amp;amp;&amp;amp; features.length === 1) {

                                //var feat = layer.layerObject.getSelectedFeatures();
                                //console.log(features[0])
                                this.map.centerAt(features[0].geometry);
                                this.map.graphics.clear();
                                var selSymbolJson = {
                                    "color": [
                                        0,
                                        0,
                                        0,
                                        0
                                    ],
                                    "size": 30.5,
                                    "angle": 0,
                                    "xoffset": 0,
                                    "yoffset": 0,
                                    "type": "esriSMS",
                                    "style": "esriSMSCircle",
                                    "outline": {
                                        "color": [
                                            0,
                                            255,
                                            250,
                                            255
                                        ],
                                        "width": 2.50,
                                        "type": "esriSLS",
                                        "style": "esriSLSSolid"
                                    }
                                }

                                var attributes = {};
                                attributes['appId'] = features[0]['attributes'].appId //this.appId
                                attributes['reviewStatus'] = features[0]['attributes'].reviewStatus
                                attributes['facilityId'] = features[0]['attributes'].facilityId
                                attributes['facilityType'] = features[0]['attributes'].facilityType
                                attributes['facilityName'] = features[0]['attributes'].facilityName
                                attributes['permitId'] = features[0]['attributes'].permitId
                                attributes['OBJECTID'] = features[0]['attributes'].OBJECTID

                                this.selGraphic = new Graphic(features[0].geometry, symbolJsonUtils.fromJson(selSymbolJson), attributes)

                                this.map.graphics.clear();
                                this.map.graphics.add(selGraphic);
                                this.editToolbar = new Edit(this.map);
                                this.editToolbar.activate(Edit.MOVE, selGraphic);

                                this.editToolbar.on('graphic-move-stop', function (evt) {
                                    var serverSideScratchLayerFacs = new FeatureLayer("urlToEditableFeatureService/FeatureServer/0" + '?token=uV6qzrCtV3hX_4XCqy_u9u3sVAb3QxuT86L1mTwlHdu1lcfPjOrer2vpjXoi61Y3wh8Fz82hsjqlosBKnOsdPF5m3wTW6wF9GmlRLgaPUQk.'); // + window.atob(tok));
                                    var scratchQueryFacs = new Query();
                                    scratchQueryFacs.where = "facilityId = '" + e.target.id + "'"
                                    serverSideScratchLayerFacs.queryFeatures(scratchQueryFacs);
                                    serverSideScratchLayerFacs.selectFeatures(scratchQueryFacs).then(function (features) {

                                        serverSideScratchLayerFacs.applyEdits([selGraphic], null, [features[0]])                                        
                                        this.editToolbar.deactivate()
                                        layer.layerObject.refresh()
                                    })
                                })                                                             
                            }
                        });
                    }
                }
            })
        },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 20:24:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1174799#M14753</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-05-17T20:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1175009#M14754</link>
      <description>&lt;P&gt;You're running the applyEdit method on a new featurelayer (serverSideScratchLayerFacs), not the layer (layer.layerObject) where the original point feature resides.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 13:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1175009#M14754</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-05-18T13:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: .applyEdits not updating feature service layer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1175025#M14755</link>
      <description>&lt;P&gt;Yeah, was my oversight when first attempt at this then realized that&amp;nbsp;&lt;SPAN&gt;layer.layerObject is a view only service in the webmap source to this WAB app.&amp;nbsp;&amp;nbsp;serverSideScratchLayerFacs is the edit service to the same data source.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I still think its close because it does in fact applyEdits and adds the selGraphic point feature with attributes!&amp;nbsp; But I'm not seeing why features[0] is not getting deleted at the same time.&lt;/P&gt;&lt;P&gt;Thanks again, I'm making progress with you're input!&lt;/P&gt;&lt;P&gt;Edit: final change works to setup applyEdits with the update instead of add/delete.&amp;nbsp; Ken I used all of your input/posts to solve this so I just marked the one that was super useful to get the correct workflow.&amp;nbsp; Much appreciated!&lt;/P&gt;&lt;P&gt;This is the last change that worked:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;serverSideScratchLayerFacs.applyEdits(null, [selGraphic], null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 13:59:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/applyedits-not-updating-feature-service-layer/m-p/1175025#M14755</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-05-18T13:59:04Z</dc:date>
    </item>
  </channel>
</rss>

