Solved! Go to Solution.
It took me about a year to fully understand this concept, but adding data to the map and creating an Experience Builder datasource are two entirely separate things. Adding a layer to the map will make it appear visually, but many of the advanced data functions will not be available.
To get all of the data functions, you must convert your FeatureLayer to a datasource and send a message to the framework notifying it of a new datasource. Your code does not do these things. If you need all of the data functions, you need to use some code like in the link above. The solution in this post found a better version of my code. https://community.esri.com/t5/arcgis-experience-builder-questions/loss-of-renderer-with-runtime-crea...
Also here is a complete working widget that add and removes layers as datasources. https://community.esri.com/t5/experience-builder-custom-widgets/add-remove-layers-2-0/ta-p/1540096
It took me about a year to fully understand this concept, but adding data to the map and creating an Experience Builder datasource are two entirely separate things. Adding a layer to the map will make it appear visually, but many of the advanced data functions will not be available.
To get all of the data functions, you must convert your FeatureLayer to a datasource and send a message to the framework notifying it of a new datasource. Your code does not do these things. If you need all of the data functions, you need to use some code like in the link above. The solution in this post found a better version of my code. https://community.esri.com/t5/arcgis-experience-builder-questions/loss-of-renderer-with-runtime-crea...
Also here is a complete working widget that add and removes layers as datasources. https://community.esri.com/t5/experience-builder-custom-widgets/add-remove-layers-2-0/ta-p/1540096
Awesome @JeffreyThompson2 , thank you so much!
Thanks! I suspected this to be the case as I was confused about adding data sources and adding a layer to the map. There is also client and server side output data sources, which I don't quite understand. I am just trying to implement addition of output feature layer to the map but rather do it in the same way that Add Data widget does it. Runtime data source sample widget doesnt help much...
Be aware that there is a major breaking change at 1.16. The devs removed the hacky way we have been making datasources and created some new functions to facilitate the process. This post has code for making a datasource from an API FeatureLayer in 1.16.
Thanks for the headsup. I have to use 1.14 ExB Dev due to it being the version compatible with Enterprise 11.3. I import the custom widget to Portal.
Is this method you mention the same way Add Data widget is doing it? I am currently trying to reverse engineer it. I see it publishes a message and I should be able to use "Add to Map" data action trigger on the Map Widget when the data source is created.
I don't think it's exactly the same, but it is similar.