Greetings,
I am having considerable trouble getting the results from a relationship query to populate an attribute inspector(for editing purposes). I have been working on this for a few weeks now and am having no luck.
Takes two clicks before the related info will pop up in a infowindow.
function findRelatedRecords(features) {
var relatedTopsQuery = new esri.tasks.RelationshipQuery();
relatedTopsQuery.outFields = ["*"];
//relatedTopsQuery.relationshipId = 3;
relatedTopsQuery.relationshipId = 0;
//relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
wellFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
console.log("related recs: ", relatedRecords);
if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
console.log("No related records for ObjectID_1: ", features[0].attributes.OBJECTID_1);
return;
}
var fset = relatedRecords[features[0].attributes.OBJECTID];
//var fset = relatedRecords[features[0].attributes.OBJECTID];
items = dojo.map(fset.features, function(feature) {
return feature.attributes;
});
function findWells(evt) {
var asdf = evt.layers[0].layer;
var selectQuery = new Query();
var selectionQuery = new esri.tasks.Query();
var tol = map.extent.getWidth()/map.width * 5;
var x = evt.mapPoint.x;
var y = evt.mapPoint.y;
var queryExtent = new esri.geometry.Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);
selectionQuery.geometry = queryExtent;
asdf.selectFeatures(selectionQuery, FeatureLayer.SELECTION_NEW, function(features) {
//store the current feature
updateFeature = features[0]; console.log("adf");
map.infoWindow.setTitle(features[0].getLayer().name); console.log("adf");
map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)); console.log("adf");
});
};
// I am also unable to get the attribute inspector to pull up a non related feature BELOW
var layerInfos = [{
'featureLayer': wellFeatureLayer1,
'showAttachments': false,
'isEditable': true,
'fieldInfos': [
{'fieldName': 'SERVICE_ID', 'isEditable':true, 'tooltip': 'Current Status', 'label':'Status:'}
]
}];
var attInspector = new AttributeInspector({
layerInfos:layerInfos
}, domConstruct.create("div"));
Any help would be very much appreciated.
Solved! Go to Solution.
Will, I don't understand the code in your jsfiddle, and there are many issues in there. It seems like you added a bunch of code that just tries to do similar things to what I was already doing, but then you also left my code in there. It doesn't make sense. Additionally, the sample map service you're trying to use doesn't have a FeatureService behind it, so I don't think its a good service to test this scenario out. Having a jsfiddle built against the real FeatureServices you are working with would really help.
- Don't create multiple instances of AttributeInspector, just add all your editable layers to one instance via layerInfos.
- Don't let the 'related table' concept confuse you, it's just another FeatureLayer that the AttributeInspecor can edit.
- Every layer added to the layerInfos of the AttributeInspector should have a list of fields you want to view/edit.
- If defining the editable fields dynamically from the FeatureLayer, then make sure the layer is 'loaded' before accessing the 'fields' collection.
I hope this helps
Ok, yeah that was pretty bad. Not sure what went on there, but I assure you I haven't been drinking.
I've loaded the layers in like in your samples, but the non related layer is still not popping up. I fixed the Fiddle Edit fiddle - JSFiddle , and it is returning the related table info but not the non related feature.(I realize that is just a Map Service, but it should still return a value. right?)
I think this is due to the all the selections running through the onSourceLayerClick(evt), not finding a value and turning up "No Related Items".
I appreciate all your help, John, do you think you could take one more look at it???
Will, there are several considerations to look at for this use case. The relationship query is specific to a layer, so the 'click' event should be on that layer, not the map. This routine only selects items from the related table, so those are the only ones that show up in the AttributeInspector. If you wish to see features from a different layer in the AttributeInspector you'll have to create a different 'selection' routine that is specific to that layer. You could have a generic 'selection' routine, but then you'd have to put logic in it to deal with each layer in a specific way.
Good stuff, John. You got me out of a hell of a pickle. Appreciate all the help.