I'm attempting to create a custom widget and struggling to query data from a feature layer. When I step thru the debugger, everything works, but no data rows are ever returned. The debugger shows the DataSource does indeed exist and everything looks fine, I simply cannot get any data to return. Here is a stripped down version of the code:
Solved! Go to Solution.
Hi There,
Not sure about casting to QueriableDataSource (I've not used it in my workflows), I cast to a FeatureLayerDataSource and then query from there. The other recommendation I would make is to always include a catch in your promises, as it will allow you to see any errors generated from the server, otherwise they can fail silently. See code snippet below
let dsm = DataSourceManager.getInstance();
// use the settings to get the datasource by id.
let ds = dsm.getDataSource(this.props.useDataSources[1].dataSourceId) as FeatureLayerDataSource;
//I'm not creating a seperate object for query parameters, just passing them in like so
ds.query({ where: '1 = 1', returnGeometry: false, pageSize: 2 })
.then((response) =>
{
//Log the respone
console.log(response)
})
.catch((error) => {
//Catch any issues and log to the console
console.error(error)
})
.finally(() => {
console.log('Operation completed')
})
Hopefully this helps.
Cheers
Hi There,
Not sure about casting to QueriableDataSource (I've not used it in my workflows), I cast to a FeatureLayerDataSource and then query from there. The other recommendation I would make is to always include a catch in your promises, as it will allow you to see any errors generated from the server, otherwise they can fail silently. See code snippet below
let dsm = DataSourceManager.getInstance();
// use the settings to get the datasource by id.
let ds = dsm.getDataSource(this.props.useDataSources[1].dataSourceId) as FeatureLayerDataSource;
//I'm not creating a seperate object for query parameters, just passing them in like so
ds.query({ where: '1 = 1', returnGeometry: false, pageSize: 2 })
.then((response) =>
{
//Log the respone
console.log(response)
})
.catch((error) => {
//Catch any issues and log to the console
console.error(error)
})
.finally(() => {
console.log('Operation completed')
})
Hopefully this helps.
Cheers
Thanks for the help Grant. I used that exact code and set a breakpoint to debug the steps. When I stepped thru the ds.query, it blew right past all the statements and went to the end of my function. When I examine the "ds" properties in developer tools, everything looks fine. URL, schema, etc. I verified that data does indeed exist in the layer.
I'll keep at it. I know it's something on my end and it's been a while since I've done much development.
Hi Paul
Unless you set a break point on the return statements, eg console.log etc, it will pass over it as its an async process, so it will run the code in the background after which it will jump in to either the then/catch functions.
Try that and see if you start to see any results?
Cheers
Grant - thank you so much! I had async in the back of my head, but was too impatient. All is now working and I can move on.
I appreciate the help.