I am developing a very simple widget that generates a feature layer. This widget does not have any setting file as it does not require any input data sources. I would like to create an output data source with the feature layer data. Here is the beginning of my widget.tsx code:
const [myDSout, setMyDSout] = useState<FeatureLayerDataSource>(null)
const outputDsJsons: DataSourceJson[] = [{
id: "widget_1_ouput",
isOutputFromWidget: true,
isDataInDataSourceInstance: true,
label: "MyDSoutput",
type: "FEATURE_LAYER"
}]
DataSourceManager.getInstance().createDataSource(outputDsJsons[0]).then((result: FeatureLayerDataSource) => {
setMyDSout(result);
});
I got the following message: "Datasource without origin data source must save the schema in app config"
I have manually modified the entry for "widget_1_ouput" in the dataSources section of the config file of my app (the one found in the server\public\apps\3\resources\config) with an entry schema without any effects.
Obviously this is not the right approach, so here is my question: What is the right way to save a schema in an app config?
Thanks for any comments.
Solved! Go to Solution.
Hi Cathrine,
thank you for your sample.
I am not using the buildRecord() method, so I do not encouter this problem.
Based on your error message, it looks like you are not getting the DataSource object using the getOutputDataSource method.
The error says that the buildRecord method does not exist on the object you get.
I would try setting a breakpoint on that line and see what the minified variable t is.
Or put a control statement in the console:
console.log(getOutputDataSource().id) to see if it finds the correct data source.
Or try creating a Recod using the FeatureDataRecordImpl method from 'jimu-core/data-source', for example:
const record = new FeatureDataRecordImpl(myline1, getOutputDataSource());
But I think the problem is in getting the output datasource.
Good luck.
Jakub
Hi Catherine, I'm facing the same problem. Were you able to save the schema in the app config ?
Thanks for reply.
Jakub
Hi Jakub,
Yes I finally came up with a solution: The implementation of
Hi Catherine,
Thanks for your answer.
Yes, I managed to set up the output datasource according to your instructions. And also by following the DataSourceJson datatype.
The other widgets now see my output datasource and
the attribute table is able to configure it successfully.
I am unable to set the data to the output datasource.
I have tried calling the following output datastore methods
setSourceRecords()
setRecord()
according to documentation:
But the attribute table does not display any data.
I also tried calling the recommended method
addSourceVersion()
What method did you use to set the data in the output datasource?
Can you attach a code sample?
Thank you.
Regards.
Jakub
Hi Cathrine,
I finally made it!
It helped me to call the updateSourceByFeatures() method to set the data
and update the datastore status to force the Attribute table to display the data:
Hi Jakub,
Glad to read it's working for you. I am curious to see how you use the updateSourceByFeatures() method.
I am including a very simple demo widget that shows how I implement output datasource. This approach works for me in the developer environment (and in the downloaded experience) but I have still a problem. When I add this widget to our portal, it does not work. I am getting this cryptic error message: "Uncaught TypeError: t.buildRecord is not a function". Do you encounter the same?
Catherine
Hi Cathrine,
thank you for your sample.
I am not using the buildRecord() method, so I do not encouter this problem.
Based on your error message, it looks like you are not getting the DataSource object using the getOutputDataSource method.
The error says that the buildRecord method does not exist on the object you get.
I would try setting a breakpoint on that line and see what the minified variable t is.
Or put a control statement in the console:
console.log(getOutputDataSource().id) to see if it finds the correct data source.
Or try creating a Recod using the FeatureDataRecordImpl method from 'jimu-core/data-source', for example:
const record = new FeatureDataRecordImpl(myline1, getOutputDataSource());
But I think the problem is in getting the output datasource.
Good luck.
Jakub
Hi Jakub,
Big thanks for your suggestions! I tried using the FeatureDataRecordImpl method from 'jimu-core/data-source' and it worked perfectly. Just wondering how did you come up with this method, I could not find it in the documentation (which really is not very friendly).
Thanks again.
Catherine
Hi Catherine,
I'm glad you made it.
This method was recommended to me by my colleague who found it somewhere in the source code of Experience builder. Yes, the documentation is not very helpful.
Jakub