Hi all,
I'm working with JS 4.6.
I want to query the table of a FeatureLayer to get all of its containing values and then push it into a JavaScript array? I can't find any sample code.
My FeatureLayer ist hosted on ArcGis Online. This is my code but I get featureset "length: 0" in my console
var queryStatesTask = new QueryTask({
url: "..."
});
var query = new Query();
queryStatesTask.execute(query).then(function(result){
console.log(result.features);
});
Solved! Go to Solution.
Michael,
Your Query Class needs a where property and outFields and optionally outSpatialReference.
var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;
Michael,
Your Query Class needs a where property and outFields and optionally outSpatialReference.
var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;
Thank you Robert for your fast reply. They are all in the same spatial reference, so I think I don't need the
query.outSpatialReference = map.spatialReference;
I still get length: 0 as result in the console
Is there something wrong with my layer? Its a "hosted feature layer" on ArcGis Online containing 59 features. It is also set as "Public (everyone)".
var queryStatesTask = new QueryTask({
url: "https://services6.arcgis.com/zsStDqlI7B7GPAe2/arcgis/rest/services/Hundestation/FeatureServer"
});
var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
queryStatesTask.execute(query).then(function(result){
console.log(result.features);
});
btw: How can I debug such things... It's very difficult to notice the problems...
Michael,
You need to use a url that is specific to the layer of the service you want to query:
https://services6.arcgis.com/zsStDqlI7B7GPAe2/ArcGIS/rest/services/Hundestation/FeatureServer/0