<?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: Data source not available in preview in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1202279#M5092</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/512652"&gt;@Danik-B&lt;/a&gt;&amp;nbsp;Do you use &lt;EM&gt;DataSourceComponent&lt;/EM&gt; in your widget?&amp;nbsp;&lt;A href="https://developers.arcgis.com/experience-builder/guide/use-data-source-in-widget/#read-and-display-the-data-in-the-widget-runtime" target="_blank"&gt;https://developers.arcgis.com/experience-builder/guide/use-data-source-in-widget/#read-and-display-the-data-in-the-widget-runtime&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In builder, all data sources will be created automatically for the&amp;nbsp;convenience of changing data setting. However, in preview, only data sources which are used will be created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Aug 2022 05:54:06 GMT</pubDate>
    <dc:creator>YueyangLi</dc:creator>
    <dc:date>2022-08-12T05:54:06Z</dc:date>
    <item>
      <title>Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1202096#M5088</link>
      <description>&lt;P&gt;Experience Builder Dev Edition 1.8.0&lt;/P&gt;&lt;P&gt;I have a custom widget where I use DataSourceManager to access a specific data source.&amp;nbsp; The odd thing is all my code works fine when I use the Live View mode in Exp Builder but fails when I preview the app.&lt;/P&gt;&lt;P&gt;When I console&amp;nbsp;&lt;SPAN&gt;DataSourceManager&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getInstance&lt;/SPAN&gt;&lt;SPAN&gt;() in Exp Builder I can see my data source in the DataSources object but when I do that in preview the data source is not there.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there something I need to do to force the data source to be available in preview?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 18:36:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1202096#M5088</guid>
      <dc:creator>Danik-B</dc:creator>
      <dc:date>2022-08-11T18:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1202279#M5092</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/512652"&gt;@Danik-B&lt;/a&gt;&amp;nbsp;Do you use &lt;EM&gt;DataSourceComponent&lt;/EM&gt; in your widget?&amp;nbsp;&lt;A href="https://developers.arcgis.com/experience-builder/guide/use-data-source-in-widget/#read-and-display-the-data-in-the-widget-runtime" target="_blank"&gt;https://developers.arcgis.com/experience-builder/guide/use-data-source-in-widget/#read-and-display-the-data-in-the-widget-runtime&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In builder, all data sources will be created automatically for the&amp;nbsp;convenience of changing data setting. However, in preview, only data sources which are used will be created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 05:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1202279#M5092</guid>
      <dc:creator>YueyangLi</dc:creator>
      <dc:date>2022-08-12T05:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1544616#M15184</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;could you elaborate on this some more? I think I am having the same issue. I am able to successfully use my widget in the experience builder developer environment, but once I try to preview my experience, my widget is unable to read my datasources. Below is a sample of my code. Line 21 seems to return undefined for the layerview datasource when previewing my experience, but in the builder mode, it works fine.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;How can I fix this?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { DataSource, React, type AllWidgetProps } from "jimu-core";
import { type IMConfig } from "../config";
import { JimuMapView, JimuMapViewComponent } from "jimu-arcgis";
import { MouseEvent, useState } from "react";
import { Dropdown, DropdownButton, DropdownItem, DropdownMenu } from "jimu-ui";
import ConditionController from "./conditionController";

const Widget = (props: AllWidgetProps&amp;lt;IMConfig&amp;gt;) =&amp;gt; {
  const [dataSources, setDataSources] = useState&amp;lt;DataSource[]&amp;gt;([]);
  const [selectedDataSource, setSelectedDataSource] = useState({
    dataSource: null,
    schema: null,
  });

  function onActiveViewChange(activeView: JimuMapView) {
    console.log(activeView);
    if (activeView) {
      activeView.whenAllJimuLayerViewLoaded().then(() =&amp;gt; {
        const layerViews = activeView.getAllJimuLayerViews();
        const dataSources = layerViews.map((layerView) =&amp;gt; {
          return layerView.getLayerDataSource();
        });

        setDataSources(dataSources);
      });
    } else {
      setDataSources([]);
    }
  }

  function handleDataSourceSelection(mouseEvent: MouseEvent&amp;lt;any, MouseEvent&amp;gt;) {
    const ds = dataSources.find(
      (ds) =&amp;gt; ds.id === (mouseEvent.target as HTMLInputElement).value
    );

    setSelectedDataSource({ dataSource: ds, schema: ds.getSchema() });
  }

  return (
    &amp;lt;div className="widget-demo jimu-widget m-2"&amp;gt;
      &amp;lt;p&amp;gt;QueryBuilder Widget&amp;lt;/p&amp;gt;

      {dataSources.length &amp;gt; 0 &amp;amp;&amp;amp; (
        &amp;lt;Dropdown activeIcon menuItemCheckMode="singleCheck" menuRole="listbox"&amp;gt;
          &amp;lt;DropdownButton&amp;gt;
            {selectedDataSource.schema?.label || "Select a Datasource"}
          &amp;lt;/DropdownButton&amp;gt;
          &amp;lt;DropdownMenu&amp;gt;
            {dataSources.length &amp;gt; 0 &amp;amp;&amp;amp;
              dataSources.map((dataSource) =&amp;gt; {
                return (
                  &amp;lt;DropdownItem
                    active={dataSource.id === selectedDataSource.dataSource?.id}
                    value={dataSource.id}
                    key={dataSource.id}
                    onClick={handleDataSourceSelection}
                  &amp;gt;
                    {dataSource.getSchema().label}
                  &amp;lt;/DropdownItem&amp;gt;
                );
              })}
          &amp;lt;/DropdownMenu&amp;gt;
        &amp;lt;/Dropdown&amp;gt;
      )}
      {selectedDataSource.schema &amp;amp;&amp;amp; selectedDataSource.schema.fields &amp;amp;&amp;amp; (
        &amp;lt;ConditionController
          fields={Object.keys(selectedDataSource.schema.fields).map(
            (k) =&amp;gt; selectedDataSource.schema.fields[k]
          )}
          key={selectedDataSource.dataSource?.id}
        /&amp;gt;
      )}
      &amp;lt;JimuMapViewComponent
        useMapWidgetId={props.useMapWidgetIds?.[0]}
        onActiveViewChange={onActiveViewChange}
      /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 05:34:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1544616#M15184</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-10-02T05:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1546386#M15270</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/763368"&gt;@PartyPelican&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;For performance reason, JimuLayerView will not automatically create data source. If data source has been created by some widgets, then JimuLayerView.getLayerDataSource() gets the data source. If the data source has not been created, you can create the data source through the asynchronous method JimuLayerView.createLayerDataSource().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 03:24:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1546386#M15270</guid>
      <dc:creator>QunSun</dc:creator>
      <dc:date>2024-10-08T03:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1548250#M15426</link>
      <description>&lt;P&gt;The createLayerDataSource method worked for me, but I don't actually see this method documented by ESRI. I do see the DataSourceManager methods for creating a datasource but when trying to pass the&amp;nbsp;&lt;SPAN&gt;layerDataSourceId to DataSourceManager.getInstance().createDataSource() I get the error that the datasource could not be created. Do you know why that is?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2024 03:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1548250#M15426</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-10-12T03:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data source not available in preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1548354#M15428</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/763368"&gt;@PartyPelican&lt;/a&gt;&amp;nbsp;It is expected&amp;nbsp;&lt;SPAN&gt;DataSourceManager.getInstance().createDataSource() fails to create a layer data source. DataSourceManager needs a rootDataSourceId to know which map the layer belongs to. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;We recommend using &amp;nbsp;DataSourceManager.getInstance().&lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/DataSourceManager/#createDataSourceByUseDataSource" target="_blank" rel="noopener"&gt;createDataSourceByUseDataSource&lt;/A&gt;({ dataSourceId: layerDataSourceId, mainDataSourceId: layerDataSourceId, rootDataSourceId: mapDataSourceId }).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 06:34:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/data-source-not-available-in-preview/m-p/1548354#M15428</guid>
      <dc:creator>YueyangLi</dc:creator>
      <dc:date>2024-10-14T06:34:14Z</dc:date>
    </item>
  </channel>
</rss>

