<?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 Delete all features on website refresh (or end of session) in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/delete-all-features-on-website-refresh-or-end-of/m-p/1524464#M14387</link>
    <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I am trying to achieve the following:&lt;/P&gt;&lt;P&gt;In an application built with experience builder, using the editor widget, delete all records when the website (application) is refreshed. I know that the whole purpose of the editor widget is to keep all data between sessions (the opposite of Draw widget which I do not want to use for different reasons). I have installed the Experience builder developer edition and trying to find the best option to go about it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking of two options:&lt;/P&gt;&lt;P&gt;1. Automatize it somehow "behind the scenes" to delete all data when the session is refreshed.&lt;/P&gt;&lt;P&gt;2. Enable a new "delete all data" button that the user can click.&lt;/P&gt;&lt;P&gt;I would appreciate any help to point me in the right direction!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2024 15:56:11 GMT</pubDate>
    <dc:creator>bogdanpalade2</dc:creator>
    <dc:date>2024-08-20T15:56:11Z</dc:date>
    <item>
      <title>Delete all features on website refresh (or end of session)</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/delete-all-features-on-website-refresh-or-end-of/m-p/1524464#M14387</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I am trying to achieve the following:&lt;/P&gt;&lt;P&gt;In an application built with experience builder, using the editor widget, delete all records when the website (application) is refreshed. I know that the whole purpose of the editor widget is to keep all data between sessions (the opposite of Draw widget which I do not want to use for different reasons). I have installed the Experience builder developer edition and trying to find the best option to go about it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking of two options:&lt;/P&gt;&lt;P&gt;1. Automatize it somehow "behind the scenes" to delete all data when the session is refreshed.&lt;/P&gt;&lt;P&gt;2. Enable a new "delete all data" button that the user can click.&lt;/P&gt;&lt;P&gt;I would appreciate any help to point me in the right direction!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 15:56:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/delete-all-features-on-website-refresh-or-end-of/m-p/1524464#M14387</guid>
      <dc:creator>bogdanpalade2</dc:creator>
      <dc:date>2024-08-20T15:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all features on website refresh (or end of session)</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/delete-all-features-on-website-refresh-or-end-of/m-p/1528549#M14578</link>
      <description>&lt;P&gt;I will reply here to my own question because I found a solution: for&amp;nbsp; simplicity I chose the second option, an unique button that will delete all data from the feature layer shown in the map widget. Here s the code of the widget.tsx:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/** @jsx jsx */
import { React, jsx, AllWidgetProps } from 'jimu-core';
import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis';
import { Button } from 'jimu-ui';
import FeatureLayer from 'esri/layers/FeatureLayer';

interface State {
  jimuMapView: JimuMapView;
}

export default class DeleteAllFeaturesWidget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;{}&amp;gt;, State&amp;gt; {
  constructor(props) {
    super(props);
    this.state = {
      jimuMapView: null,
    };
  }

  handleActiveViewChange = (jimuMapView: JimuMapView) =&amp;gt; {
    this.setState({ jimuMapView });
  }

  deleteAllFeatures = () =&amp;gt; {
    const { jimuMapView } = this.state;

    if (jimuMapView &amp;amp;&amp;amp; jimuMapView.view) {
      const layer = jimuMapView.view.map.layers.find((l) =&amp;gt; l.type === 'feature') as FeatureLayer;
      
      if (layer) {
        layer.queryFeatures().then((results) =&amp;gt; {
          const objectIds = results.features.map((feature) =&amp;gt; feature.attributes[layer.objectIdField]);
          if (objectIds.length &amp;gt; 0) {
            layer.applyEdits({
              deleteFeatures: objectIds.map((objectId) =&amp;gt; ({ objectId })),
            }).then(() =&amp;gt; {
              alert('All features deleted successfully.');
            }).catch((error) =&amp;gt; {
              console.error('Failed to delete features:', error);
              alert('Failed to delete features.');
            });
          } else {
            alert('No features found to delete.');
          }
        }).catch((error) =&amp;gt; {
          console.error('Failed to query features:', error);
        });
      } else {
        alert('No feature layer found in the map.');
      }
    } else {
      alert('MapView is not ready.');
    }
  }

  render() {
    return (
      &amp;lt;div className="widget-delete-all-features"&amp;gt;
        &amp;lt;JimuMapViewComponent
          useMapWidgetId="widget_1"
          onActiveViewChange={this.handleActiveViewChange}
        /&amp;gt;

        &amp;lt;Button type="primary" onClick={this.deleteAllFeatures}&amp;gt;Delete All&amp;lt;/Button&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Cheers!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 10:31:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/delete-all-features-on-website-refresh-or-end-of/m-p/1528549#M14578</guid>
      <dc:creator>bogdanpalade2</dc:creator>
      <dc:date>2024-08-28T10:31:32Z</dc:date>
    </item>
  </channel>
</rss>

