I have a polygon layer where one polygon matches multiple records in a table. I use JoinDataSource() to join these two items so I can set the definition expression of the polygon layer based on a field in the table. When I go to set the popup content for this polygon feature I need to query the records in the table that are related with the polygon layer. To use a relationship query, you need the objectId of the polygon, but I can't get that using feature.attributes.fieldName because the field name itself has a bunch of periods in it due to the database and tables names being prefixed on it. Using something like this won't work because javascript misinterprets the periods:
feature.attributes.HabitatManagement.DBO.MgmtTracts.OBJECTID
How do I get around this?
Here is the relationship query code:
function mgmtPopupContent(feature) {
var OID = feature.attributes.HabitatManagement.DBO.MgmtTracts.OBJECTID;
var relatedQuery = new RelationshipQuery();
relatedQuery.outFields = ["*"];
relatedQuery.relationshipId = 0;
relatedQuery.objectIds = OID;
hbMgmtTractFL.queryRelatedFeatures(relatedQuery, function(relatedRecords) {
//set popup content
}
}
Solved! Go to Solution.
Since feature.attributes returns an object, I just resolved to indexing into it using the full field name as the key. Note, I had to query the related records on the non-joined feature layer, I cannot query related records of a dynamic layer.
function mgmtPopupContent(feature) {
for (var attrb in feature.attributes) {
if (attrb == "HabitatManagement.DBO.MgmtTracts.OBJECTID") {
var OID = feature.attributes[attrb];
console.log(OID);
}
}
var relatedQuery = new RelationshipQuery();
relatedQuery.outFields = ["*"];
relatedQuery.relationshipId = 0;
relatedQuery.objectIds = [OID];
noJoinMgmtTractFL.queryRelatedFeatures(relatedQuery, function (relatedRecords) {
console.log(relatedRecords);
});
}
Since feature.attributes returns an object, I just resolved to indexing into it using the full field name as the key. Note, I had to query the related records on the non-joined feature layer, I cannot query related records of a dynamic layer.
function mgmtPopupContent(feature) {
for (var attrb in feature.attributes) {
if (attrb == "HabitatManagement.DBO.MgmtTracts.OBJECTID") {
var OID = feature.attributes[attrb];
console.log(OID);
}
}
var relatedQuery = new RelationshipQuery();
relatedQuery.outFields = ["*"];
relatedQuery.relationshipId = 0;
relatedQuery.objectIds = [OID];
noJoinMgmtTractFL.queryRelatedFeatures(relatedQuery, function (relatedRecords) {
console.log(relatedRecords);
});
}