Is there a way to query and display features based on attributes in a related table? The main feature service doesn't have the attributes I need to query by. Since there is no geometry in the related tables how do I return the main features that have the related values needed to display on the map?
Jay,
You do a standard QueryTask on the Table and get the records ObjectId. Then you can use the RelationshipQuery using that Id to get the main feature that the Id relates to that does have geometry.
RelationshipQuery | API Reference | ArcGIS API for JavaScript 3.23
Robert
Here is what I have so far but the geometry is not getting returned. This is the 4.5 API as well.
document.getElementById("layer-select").addEventListener(
"change",
function doQuery() {
var layerSelect = document.getElementById("layer-select");
resultsLayer.removeAll();
console.log(layerSelect.value);
coreSample = layerSelect.value;
var query = new Query();
query.where = "1 = 1";
queryWells.executeForIds(query).then(function(wellOids){
console.log(wellOids);
console.log(coreSample);
relationQuery2 = new RelationshipQuery({
objectIds: [wellOids],
definitionExpression: "TYPE =" + coreSample,
outFields: ["UWI"],
returnGeometry: true,
relationshipId: 0
});
//console.log(relationQuery2);
queryWells.executeRelationshipQuery(relationQuery2).then(function(selectTypes){
console.log(selectTypes);
console.log("relate");
});
});
});
Jay,
Something looks backwards in your code there. If queryWells is the related table why are you doing a 1=1 query on it? I thought you said you wanted to query the related table for certain attributes and then get the related Feature?
queryWells is the main feature service. I query that (1 = 1) for all ObjectIDs to then feed them to the relationshipQuery (welOIDs). Does that make sense?
OK,
Like I said you are going about it backwards then. You need to Query the Table for your desired attributes (not the FeatureLayer) then get the ObjectId of the record and do the relationship query on the Fearturelayer. Right now you are doing the opposite of this.
Ok, I was not aware that I could reverse the order of the related query. Thought the OIDs of the main feature were needed. I'll try that. Thanks Robert
Hi Jay, Did you come up with some code that works? I'd love to see it. Thanks, Dake
Dake
No unfortunately not. I ended up using a python script to read the related data and add a field to the wells feature class with the data i needed to query. I'd like to revisit this problem though sometime.
Dake
Got this working finally for another app in development. Let me know if you have any questions.
var speciesQueryTask = new QueryTask ({
url: "https://services.arcgis.com/View/FeatureServer/4",
});
//Query the related table for names that match commonName field with the user selected option in the DOM
var speciesQuery = new Query();
speciesQuery.outFields = ["*"];
speciesQuery.where = "commonName = '" + speciesCommonName + "'";
speciesQueryTask.execute(speciesQuery).then(function(results){
console.log(results.features);
var oldArray = results.features;
specidArray = [];
oldArray.forEach(function(ftrs) {
var att = ftrs.attributes.OBJECTID;
specidArray.push(att);
});
//setup the relationship query with the plantSites featurelayer using the objectIDs from the related table query
var querySites = new RelationshipQuery({
objectIds: specidArray,
outFields: ["*"],
returnGeometry: true,
relationshipId: 0,
});
speciesQueryTask.executeRelationshipQuery(querySites).then(function(rslts) {
console.log(rslts);
});
});