<?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: Custom Widget Datasources Not Loading in Experience Builder Dev Preview in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1545465#M15228</link>
    <description>&lt;P&gt;I gave it a try, but had no luck, Its bizarre, it works in the builder view of experience builder, but fails in preview.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Oct 2024 02:50:44 GMT</pubDate>
    <dc:creator>PartyPelican</dc:creator>
    <dc:date>2024-10-04T02:50:44Z</dc:date>
    <item>
      <title>Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1544617#M15185</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I was wondering if anyone has experienced/fixed this issue. My widget works as expected when in experience builder developer edition. However, when viewing the experience in preview mode, my datasources don't seem to load and the widget throws an error. Line 21 is where the datasource for each layerview should be returned, this doesn't seem to work in preview mode.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Anyone run into this issue before? I appreciate any help!&lt;/P&gt;&lt;P&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 05:50:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1544617#M15185</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-10-02T05:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1544701#M15192</link>
      <description>&lt;P&gt;Try putting a console log between line 17 and 18. Sometimes it takes several microseconds for a complex object to write to memory, so activeview might be evaluating false at the if statement, but the console in the browser will show the full object after it is loaded. This kind of problem can be very confusing since your console is lying to you. Before the if statement, I think you need a delay function like setTimeout or reactiveUtils. This one should get you into the if.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils
  .whenOnce(() =&amp;gt; activeview.view.ready)
    .then(() =&amp;gt; {
       if(activeView){...}
    }
  )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Oct 2024 12:39:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1544701#M15192</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-10-02T12:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1545465#M15228</link>
      <description>&lt;P&gt;I gave it a try, but had no luck, Its bizarre, it works in the builder view of experience builder, but fails in preview.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 02:50:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1545465#M15228</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-10-04T02:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1545530#M15230</link>
      <description>&lt;P&gt;Another thing to keep in mind is that the onActiveViewChange() function only activates when the jimuMapView is changed, as in the entire object is totally replaced. I think this function should be called when the project loads as it goes from undefined to defined, but it's possible that the function is not being called. My widgets almost always have an useEffect() function similar to this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	useEffect(() =&amp;gt; {
		//Once the map is loaded and ready add the initially active layers
		if (jimuMapView) {
			reactiveUtils
			  .whenOnce(() =&amp;gt; jimuMapView.view.ready)
			    .then(() =&amp;gt; {
				//stuff to do when the widget loads   
			    }
			)
		}
		
	}, [jimuMapView])&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Oct 2024 12:22:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1545530#M15230</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-10-04T12:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1580502#M17170</link>
      <description>&lt;P&gt;I am running into the same issue. Mine is a widget that was developed in ArcGIS Experience Builder Dev Edition version 1.12. The original installation was on an ArcGIS Enterprise 11.2 Portal, and everything worked well. The problem only came up once the ArcGIS Enterprise system was upgraded to 11.3. There are some breaking changes noted for data sources under the jimu-core header in the 1.14 Experience Builder version associated with AGE 11.3&amp;nbsp;&lt;A href="https://developers.arcgis.com/experience-builder/guide/1.14/whats-new/#breaking-changes," target="_blank" rel="noopener"&gt;https://developers.arcgis.com/experience-builder/guide/1.14/whats-new/#breaking-changes.&lt;/A&gt;&amp;nbsp;I'm not yet seeing why this would result in the data sources being defined in the Builder view context, and then fall apart in the context when the app is previewed or launched... I will post a solution if I find one though!&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/727644"&gt;@TimWestern&lt;/a&gt;&amp;nbsp;any chance you can provide insights here?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 19:45:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1580502#M17170</guid>
      <dc:creator>EmmaHatcher</dc:creator>
      <dc:date>2025-01-30T19:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Widget Datasources Not Loading in Experience Builder Dev Preview</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1581186#M17195</link>
      <description>&lt;P&gt;Hope this helps people having the same issue but apparently datasources are created on demand, they're not all loaded by default. The solution is to use&amp;nbsp;&lt;SPAN&gt;jimuLayerView.createLayerDataSource(). You can read about it here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/Esri/arcgis-experience-builder-sdk-resources/issues/193" target="_blank" rel="noopener"&gt;https://github.com/Esri/arcgis-experience-builder-sdk-resources/issues/193&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 08:49:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-datasources-not-loading-in/m-p/1581186#M17195</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2025-02-14T08:49:12Z</dc:date>
    </item>
  </channel>
</rss>

