<?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 Send Data Source from Custom Widget to Table Widget in Experience Builder Custom Widgets</title>
    <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1478687#M329</link>
    <description>&lt;P&gt;So, I have a custom widget, where the user can select a layer from a map. From there he can choose a field, an operator and input a value. This creates a query for the layer and I set Field Out to "*". So basically, I am retrieving all items that match the query with all their fields. I would like to send this response, all the items with all their fields with respective values to the table widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget.tsx:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;try {
      const result = await layer.queryFeatures(query);
      const resultData = result.features.map((feature) =&amp;gt; ({
        attributes: feature.attributes,
        geometry: feature.geometry,
      }));
      console.log("result=", result);
      props.dispatch(appActions.widgetStatePropChange("attribute_table", "queryResult", resultData));
      highlightAndZoomToFeatures(result.features);

      const dataSourceManager = DataSourceManager.getInstance();
      const outputDsId = `${props.id}-output`;
      const outputDataSource = dataSourceManager.getDataSource(outputDsId) as FeatureLayerDataSource;

      if (outputDataSource) {
        const dataRecords = result.features.map(feature =&amp;gt; outputDataSource.buildRecord(feature));

        const fields = result.fields.reduce((acc, field) =&amp;gt; {
          acc[field.name] = {
            jimuName: field.name,
            name: field.name,
            alias: field.alias,
            type: field.type,
            esriType: field.esriType
          };
          return acc;
        }, {});

        const updatedSchema = Immutable({
          idField: "__OBJECTID",
          fields
        });

        outputDataSource.setSchema(updatedSchema);

        outputDataSource.setSourceRecords(dataRecords);
        outputDataSource.setStatus(DataSourceStatus.Unloaded);
        outputDataSource.setCountStatus(DataSourceStatus.Unloaded);

        const dataActionManager = DataActionManager.getInstance();
        const actions = dataActionManager.getActions();
        const viewInTableAction = actions.find(action =&amp;gt; action.id === 'widget_6-viewInTable');

        if (viewInTableAction) {
          const dataRecordSet: DataRecordSet = {
            dataSource: outputDataSource,
            records: dataRecords,
            name: query.where
          };
          viewInTableAction.onExecute([dataRecordSet], DataLevel.Records, props.id);
        } else {
          console.error("View in Table action not found");
        }
      } else {
        console.error("Output data source not found");
      }
    } catch (error) {
      console.error("Error executing query:", error);
    }
  };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;setting.tsx:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* eslint-disable */
import { React } from 'jimu-core';
import { AllWidgetSettingProps } from 'jimu-for-builder';
import { MapWidgetSelector } from 'jimu-ui/advanced/setting-components';
import { DataSourceJson, DataSourceTypes } from 'jimu-core';
const { useEffect } = React;

const Setting = (props: AllWidgetSettingProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const onMapWidgetSelected = (useMapWidgetIds: string[]) =&amp;gt; {
    props.onSettingChange({
      id: props.id,
      useMapWidgetIds: useMapWidgetIds
    });
  };

  useEffect(() =&amp;gt; {
    const outputDsJsons: DataSourceJson[] = [{
      id: `${props.id}-output`,
      type: DataSourceTypes.FeatureLayer,
      label: "Query Result Layer",
      originDataSources: [],
      isDataInDataSourceInstance: true
    }];

    props.onSettingChange({
      id: props.id,
      useDataSources: []
    }, outputDsJsons);
  }, []);

  return (
    &amp;lt;div className="widget-setting-demo"&amp;gt;
      &amp;lt;MapWidgetSelector useMapWidgetIds={props.useMapWidgetIds} onSelect={onMapWidgetSelected} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Setting;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this, in the table widget I can select Query Result Layer output as data action. However, whenever I try to execute the query I get this error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-25 000421.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/105374iD33F481C476F6483/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-25 000421.png" alt="Screenshot 2024-05-25 000421.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would appreciate any kind of help. Please let me know if you need more info... Thanks!&lt;/P&gt;&lt;P&gt;Note: I tested this with a custom table, everything works as expected.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2024 23:07:12 GMT</pubDate>
    <dc:creator>Esprit3</dc:creator>
    <dc:date>2024-05-24T23:07:12Z</dc:date>
    <item>
      <title>Send Data Source from Custom Widget to Table Widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1478687#M329</link>
      <description>&lt;P&gt;So, I have a custom widget, where the user can select a layer from a map. From there he can choose a field, an operator and input a value. This creates a query for the layer and I set Field Out to "*". So basically, I am retrieving all items that match the query with all their fields. I would like to send this response, all the items with all their fields with respective values to the table widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget.tsx:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;try {
      const result = await layer.queryFeatures(query);
      const resultData = result.features.map((feature) =&amp;gt; ({
        attributes: feature.attributes,
        geometry: feature.geometry,
      }));
      console.log("result=", result);
      props.dispatch(appActions.widgetStatePropChange("attribute_table", "queryResult", resultData));
      highlightAndZoomToFeatures(result.features);

      const dataSourceManager = DataSourceManager.getInstance();
      const outputDsId = `${props.id}-output`;
      const outputDataSource = dataSourceManager.getDataSource(outputDsId) as FeatureLayerDataSource;

      if (outputDataSource) {
        const dataRecords = result.features.map(feature =&amp;gt; outputDataSource.buildRecord(feature));

        const fields = result.fields.reduce((acc, field) =&amp;gt; {
          acc[field.name] = {
            jimuName: field.name,
            name: field.name,
            alias: field.alias,
            type: field.type,
            esriType: field.esriType
          };
          return acc;
        }, {});

        const updatedSchema = Immutable({
          idField: "__OBJECTID",
          fields
        });

        outputDataSource.setSchema(updatedSchema);

        outputDataSource.setSourceRecords(dataRecords);
        outputDataSource.setStatus(DataSourceStatus.Unloaded);
        outputDataSource.setCountStatus(DataSourceStatus.Unloaded);

        const dataActionManager = DataActionManager.getInstance();
        const actions = dataActionManager.getActions();
        const viewInTableAction = actions.find(action =&amp;gt; action.id === 'widget_6-viewInTable');

        if (viewInTableAction) {
          const dataRecordSet: DataRecordSet = {
            dataSource: outputDataSource,
            records: dataRecords,
            name: query.where
          };
          viewInTableAction.onExecute([dataRecordSet], DataLevel.Records, props.id);
        } else {
          console.error("View in Table action not found");
        }
      } else {
        console.error("Output data source not found");
      }
    } catch (error) {
      console.error("Error executing query:", error);
    }
  };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;setting.tsx:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* eslint-disable */
import { React } from 'jimu-core';
import { AllWidgetSettingProps } from 'jimu-for-builder';
import { MapWidgetSelector } from 'jimu-ui/advanced/setting-components';
import { DataSourceJson, DataSourceTypes } from 'jimu-core';
const { useEffect } = React;

const Setting = (props: AllWidgetSettingProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const onMapWidgetSelected = (useMapWidgetIds: string[]) =&amp;gt; {
    props.onSettingChange({
      id: props.id,
      useMapWidgetIds: useMapWidgetIds
    });
  };

  useEffect(() =&amp;gt; {
    const outputDsJsons: DataSourceJson[] = [{
      id: `${props.id}-output`,
      type: DataSourceTypes.FeatureLayer,
      label: "Query Result Layer",
      originDataSources: [],
      isDataInDataSourceInstance: true
    }];

    props.onSettingChange({
      id: props.id,
      useDataSources: []
    }, outputDsJsons);
  }, []);

  return (
    &amp;lt;div className="widget-setting-demo"&amp;gt;
      &amp;lt;MapWidgetSelector useMapWidgetIds={props.useMapWidgetIds} onSelect={onMapWidgetSelected} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Setting;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this, in the table widget I can select Query Result Layer output as data action. However, whenever I try to execute the query I get this error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-25 000421.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/105374iD33F481C476F6483/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-25 000421.png" alt="Screenshot 2024-05-25 000421.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would appreciate any kind of help. Please let me know if you need more info... Thanks!&lt;/P&gt;&lt;P&gt;Note: I tested this with a custom table, everything works as expected.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 23:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1478687#M329</guid>
      <dc:creator>Esprit3</dc:creator>
      <dc:date>2024-05-24T23:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Send Data Source from Custom Widget to Table Widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1520922#M369</link>
      <description>&lt;P&gt;Did you ever happen to find out an answer to this? I am trying to solve a similar issue.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 22:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1520922#M369</guid>
      <dc:creator>JacobAndrews</dc:creator>
      <dc:date>2024-08-13T22:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Send Data Source from Custom Widget to Table Widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1540362#M384</link>
      <description>&lt;P&gt;I have seen that error before trying to create a FeatureLayer on the client-side. FeatureLayers must have either the url property or the source property with any array of Graphic objects.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#source" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#source&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 13:55:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1540362#M384</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-09-19T13:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Send Data Source from Custom Widget to Table Widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1582333#M455</link>
      <description>&lt;P&gt;Any ideas on this? I am trying to send a featurelayer to the attribute table programmatically. Somewhat different from what you are doing but along the same lines.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 17:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1582333#M455</guid>
      <dc:creator>ericsamson_tract</dc:creator>
      <dc:date>2025-02-05T17:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Send Data Source from Custom Widget to Table Widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1585499#M465</link>
      <description>&lt;P&gt;Instead of passing programatically, I believe right way to do is to configure output data source then select it in Table widget.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 15:18:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/send-data-source-from-custom-widget-to-table/m-p/1585499#M465</guid>
      <dc:creator>UmutUcok</dc:creator>
      <dc:date>2025-02-14T15:18:30Z</dc:date>
    </item>
  </channel>
</rss>

