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, the workflow would be something like this:
Hi William,
I had attempted this almost 2 years ago (v 2.7) with no success using RelationshipQuery. After several discussions with Support, I was told it couldn't be done and would be logged as NIM081851.
Here's what ended up working for me.
https://community.esri.com/message/253305#253305
I hope it helps you out.
Kyle
Appreciate the help guys!
Kyle, I actually found your work around after I posted this yesterday. I understand the logic but I'm drawing a blank on how the query should go. I'd really like to see this work for a better understanding of query abilities.
Unfortunately, I don't have a live website to show anymore and the original feature services have been relieved of duty. Essentially, query2 is querying the attribute of the selected feature in the "related" table (activityRecord in my case). You may have success with something like:
query2.where = "serviceID = '" + selectedFeatures[0].attributes.serviceID + "'";
So long as you have the serviceID attribute present in both the feature layer and table it should come back with results. Then identify the "featureLayer" property as "activityRecord' for the "layerInfos" object, and specify "layerInfos" in "attInspector" for the "layerInfos" property. I believe it should then hydrate the Inspector with the query2 results.
If I get some time this weekend maybe I'll spin up some services for an example.
In the mean time, let me know if there's more clarity I can provide.
Kyle
Kyle, here is what I got going as of nowbut it still won't populate the field.
function initSelectToolbar(evt) {
var asdf = evt.layers[0].layer;
var selectQuery = new Query();
map.on("click", function(evt) {
var selectionQuery = new esri.tasks.Query();
var tol = map.extent.getWidth()/map.width * 15;
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");
activityRecord = new esri.layers.FeatureLayer("/Relate1/FeatureServer/1", {
infoTemplate: recordTemplate,
outFields: ["*"],
id: "activityRecord"
});
console.log("asdf1");
query2 = new esri.tasks.Query("Relate1/FeatureServer/1");
// related table field point feature selected field
query2.where = "serv_id = '" + selectedFeatures[0].attributes.Service_ID + "'";
query2.outFields = ["*"];
activityRecord.selectFeatures(query2, esri.layers.FeatureLayer.SELECTION_NEW);
console.log("asdf2");
layerInfoss = [{ 'featureLayer': activityRecord,
'showAttachments': true,
'isEditable': true
}];
console.log("asdf3");
attInspector = new esri.dijit.AttributeInspector(
{ layerInfos: layerInfoss
}, domConstruct.create("div1"));
console.log("asdf4");
recordTemplate = new esri.dijit.PopupTemplate({
title: "{PROPERTY_ID}",
fieldInfos: [
{ fieldName: "serv_id", visible: true, label: "Record:" }
],showAttachments: true
});
I have tried all sorts of combinations, so I'm not sure where exactly i'm screwing this up.
I don't see any fieldInfos set in your layerInfoss object, but all fields should be returned anyways. This table is editable, correct? It may be an issue with the recordTemplate - title property being {PROPERTY_ID}. Do you have that field in your table? If not, change it to a field name from your table. You may want to try moving line 36 "activityRecord.selectFeatures(..." under the AttributeInspector constructor at line 48.
I use Chrome for console logging. Set some objects in console.log and look to see if they are holding the expected values.
Welcome to the "combinations" club!
Kyle
Will, the workflow would be something like this:
John, that fiddle worked out pretty good. I've never used lang.hitch, so I guess I have some documentation to go through.
Thanks again.
Will, I like to use "lang.hitch(...)" to provide proper context (what 'this' means) to any function that runs async Since a lot of the JS API methods return Deferred, this becomes a simple and powerful coding pattern.
John,
I've got a pretty good understanding of your sample, but I'm running into some issues with applying it to my app. The issue is getting it to work with an existing attribute inspector with no related tables. I've tried adding the layerInfos in to the relatedTable.on("load", lang.hitch(this, function () ... No avail. I've tried using separate attribute inspectors.. no luck. each would work pending there was a map.infoWindow.setContent(attInspector1.domNode);, but not together. Any advice? I have a fiddle here Edit fiddle - JSFiddle set up to use two attribute inspectors, and it also has the combined layerInfo as well. Would you mind taking a look to see where I'm dropping the ball.