Select to view content in your preferred language

Set up a widget output data source without OriginDataSources

1908
8
Jump to solution
05-11-2023 11:26 AM
clc
by
Regular Contributor

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. 

1 Solution

Accepted Solutions
jsilhavy
Occasional Contributor

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

View solution in original post

8 Replies
jsilhavy
Occasional Contributor

Hi Catherine, I'm facing the same problem. Were you able to save the schema in the app config ?

Thanks for reply.

Jakub

0 Kudos
clc
by
Regular Contributor

Hi Jakub,

Yes I finally came up with a solution: The implementation of 

    const outputDsJsons: DataSourceJson[] = [{
      id: `${props.id}-ouput`,
      type: DataSourceTypes.FeatureLayer,
      originDataSources: [],
      schema: {
        idField: "objectid",
        fields: {......
      },
      .....
    }]
should be placed in the setting.tsx file. Then, just as the Esri example, let the framework knows which data source current widget is using and which data source current widget is outputing.
    props.onSettingChange({
      id: props.id,
      useDataSources: []
    }, outputDsJsons);
 
Finally in the widget.tsx file, you can build your records and set them to the output datasource.
Let me know if my explanations are cleared enough, thanks.
Catherine
jsilhavy
Occasional Contributor

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:

https://developers.arcgis.com/experience-builder/guide/core-concepts/data-source/#widget-output-data...

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

0 Kudos
jsilhavy
Occasional Contributor

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:

featureLayerDs.setStatus(DataSourceStatus.Unloaded);
 
Jakub
clc
by
Regular Contributor

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

 

0 Kudos
jsilhavy
Occasional Contributor

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

clc
by
Regular Contributor

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

0 Kudos
jsilhavy
Occasional Contributor

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

0 Kudos