I am upgrading an app from 4.22 to 4.24 and so far it has gone smoothly but this custom content function to populate the popup will not work now. It stops at line 17. What am I missing?
function contentSpecies(feature) {
console.log(feature);
var contentSpecies = "";
objectID = feature.graphic.attributes.OBJECTID;
console.log(objectID);
var queryURL = "https://webmaps.com/Species/MapServer/1";
var speciesSpecs = new RelationshipQuery({
outFields: ["OBJECTID", "Species", "Notes", "Status", "Known_elevation_range", "Habitat_Description", "Link_to_More_Information"],
//returnGeometry: true,
relationshipId: 0,
objectIds: [objectID]
});
//var idArray = [];
console.log(speciesSpecs);
query.executeRelationshipQuery(queryURL, speciesSpecs).then(function (rslts) {
console.log(rslts);
var features = rslts[objectID].features;
features.forEach(function(ftr) {
var t = ftr.attributes;
var species = t.Species;
contentSpecies += "<span class='bold' title='Species'><b><font size='3'><span class='uppercase'>" + species + "</span></font></b></span><br>";
var range = t.Known_elevation_range;
contentSpecies += "<span class='bold' title='Notes'><b>Known Elevation Range: </b></span>" + range + "<br/>";
var habitat = t.Habitat_Description;
contentSpecies += "<span class='bold' title='Status'><b>Habitat: </b></span>" + habitat + "<br/>";
var url = t.Link_to_More_Information;
contentSpecies += "<span class='bold' id='more' title='Status'><b>More Info: </b></span> <a target='_blank' href='" + url + "'>Link</a><br/><br>";
})
.catch((error) => {
console.log("species query error", error)
});
});
console.log("Open")
var thetitle = contentTitle(feature);
mapView.popup.open({
title: "Sensitive Amphibian Species " + thetitle,
content: contentSpecies,
outFields: ["*"],
visibleElements: {featureNaviagtion: true, closeButton: true}
})
}
Solved! Go to Solution.
I'm not sure why it would have broken, but can you try to see if you can get the ObjectIdField directly from the layer?
// from the layer if you have it
feature.graphic.attributes[layer.objectIdField]
// from the graphic if it came from a layer
feature.graphic.attributes[feature.graphic.layer.objectIdField]
It is possible the the OBJECTID field is not the ObjectID Field of the service you are querying, and your relate query returns empty results. I've seen layers with relationships have a Join_ID field as the oid.
I was able to test the executeRelationshipQuery on a sample service and got the expected results, but it's kind of tough to tell what might be happening in your scenario without a repro to look at.
Things I would recommend.
I'm not sure why it would have broken, but can you try to see if you can get the ObjectIdField directly from the layer?
// from the layer if you have it
feature.graphic.attributes[layer.objectIdField]
// from the graphic if it came from a layer
feature.graphic.attributes[feature.graphic.layer.objectIdField]
It is possible the the OBJECTID field is not the ObjectID Field of the service you are querying, and your relate query returns empty results. I've seen layers with relationships have a Join_ID field as the oid.
I was able to test the executeRelationshipQuery on a sample service and got the expected results, but it's kind of tough to tell what might be happening in your scenario without a repro to look at.
Things I would recommend.
Rene
I tried both ways for getting the objectids. Neither worked. When I try using layer.queryRelatedFeatures I get nothign as well. Now when I check the network traffic for it all , the outfields are some census fields from who knows where? Check it.
Those are not my fields, not the fields I specified in the outfields and it doesnt change when I make outfields = ["*"]
The 4.22 query url is this
Totally random! I think....
I see now that it is returning fields from the main feature layer and not the related features. The query url I am seeing is the one for the popup feature. It does not get to the point of firing the related features line of code.
It is working as intended now with layer.queryRelatedFeatures
contentSpecies = function(feature) {
var contentSpecies = "";
objectID = feature.graphic.attributes.OBJECTID;
var speciesSpecs = {
outFields: ["OBJECTID", "Species", "Notes", "Status", "Known_elevation_range", "Habitat_Description", "Link_to_More_Information"],
relationshipId: 0,
objectIds: [objectID]
}
speciesLayer.queryRelatedFeatures(speciesSpecs)
.then(function (rslts) {
var features = rslts[objectID].features;
features.forEach(function(ftr) {
var t = ftr.attributes;
var species = t.Species;
contentSpecies += "<span class='bold' title='Species'><b><font size='3'><span class='uppercase'>" + species + "</span></font></b></span><br>";
var range = t.Known_elevation_range;
contentSpecies += "<span class='bold' title='Notes'><b>Known Elevation Range: </b></span>" + range + "<br/>";
var habitat = t.Habitat_Description;
contentSpecies += "<span class='bold' title='Status'><b>Habitat: </b></span>" + habitat + "<br/>";
var url = t.Link_to_More_Information;
contentSpecies += "<span class='bold' id='more' title='Status'><b>More Info: </b></span> <a target='_blank' href='" + url + "'>Link</a><br/><br>";
})
var thetitle = contentTitle(feature);
mapView.popup.open({
title: "Sensitive Amphibian Species " + thetitle,
content: contentSpecies,
outFields: ["*"],
visibleElements: {featureNaviagtion: true, closeButton: true}
})
})
}
Thanks @ReneRubalcava