Get feature attribute when field name prefixed by table and database name?

506
1
Jump to solution
02-25-2019 06:09 AM
MKF62
by
Occasional Contributor III

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
    }
}
0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Occasional Contributor III

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);
    });
}

View solution in original post

0 Kudos
1 Reply
MKF62
by
Occasional Contributor III

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);
    });
}
0 Kudos