I create a definition expression on a featureLayer through it's relationship with table. The definition expression gets applied to the table first, then the definition expression for the featureLayer is created and applied. The definition expression is pulling records of a certain year in the table, then through it's relationship with the featureLayer I get GUIDs of those that match the pulled records in the table and set the featureLayer's definition expression based on those GUIDs. The problem is that for some years this works and for others it doesn't. I can see in the debugger that the definition expression gets created correctly for the featureLayer, but when I apply it to the featureLayer, nothing displays on the map. If I switch the year to another year, the definition expression gets applied and the appropriate polygons appear for that year. If I switch back to the previous year, again, no polygons are displayed, even though they exist for that year. It's pretty odd behavior and I'm not sure why this would be happening.
Records in the table when the definition expression is set to YearTreated = 2015.
Records in the related feature layer that match these MgmtTractIDs
My code should produce a definition expression like this for application to the featureLayer:
var de = "MgmtTractID = '{...}' OR MgmtTractID = '{...}' OR MgmtTractID = '{...}'
..so on and so forth
Apply that definition expression to the feature layer and I get nothing displayed on the map. This definition expression works for 2009, 2010, 2011, 2012, 2013, 2014, 2017, 2018, and 2019. It doesn't work for 2008, 2015, or 2016. I have checked and rechecked that the DE is being created correctly with formatting and that the MgmtTractIDs do indeed show up in the related feature layer. Everything looks fine.
on(dom.byId("data-year"), "change", function () {
var year = dom.byId("data-year").value;
if (year !== currentYear) {
hbMgmtTableFL.setDefinitionExpression('YearTreated = ' + year);
hbMgmtTableFL.refresh();
getTractDefExpression();
}
});
function getTractDefExpression() {
var recordIDs = new Query();
recordIDs.where = "1=1";
hbMgmtTableFL.queryIds(query, function (OIDs) {
if (OIDs !== null) {
var relatedRecordsQuery = new RelationshipQuery();
relatedRecordsQuery.objectIds = OIDs;
relatedRecordsQuery.outFields = ["MgmtTractID"];
relatedRecordsQuery.relationshipId = 0;
hbMgmtTableFL.queryRelatedFeatures(relatedRecordsQuery, function (fset) {
var MgmtTractIDsArr = [];
for (i = 0; i < OIDs.length; i++) {
var OID = OIDs[i];
var features = fset[OID].features;
var mgmtTractId = features[0].attributes.MgmtTractID;
if (!(MgmtTractIDsArr.includes(mgmtTractId))) {
MgmtTractIDsArr.push(mgmtTractId);
};
}
var whereClause;
for (i = 0; i < MgmtTractIDsArr.length; i++) {
if (i == 0) {
whereClause = "MgmtTractID = '" + MgmtTractIDsArr[i] + "'";
}
else {
whereClause = whereClause + " OR MgmtTractID = '" + MgmtTractIDsArr[i] + "'";
}
}
debugger;
hbMgmtTractFL.setDefinitionExpression(whereClause);
hbMgmtTractFL.refresh();
});
}
else {
debugger;
hbMgmtTractFL.setDefinitionExpression('MgmtTractID = 0');
hbMgmtTractFL.refresh();
}
});
};