I am trying to merge two ArcGIS JS API examples: Feature Layer with Popup and Query Related Records. The idea I have in mind is clicking on a country feature, retrieve all related records from a service (already prepared for relationship queries) and present those text records inside a Popup (esri.dijit.Popup).

I was interested in doing this exercise, because I like the way this Popup presents multiple results for a feature, by paging them as you can see in the first link when clicking on a tree. And it was a good match for my application with Relationship Queries. So far, I have most of the functionality already prepared and I can see the related records retrieved from the services in my firebug console. Good news.

My problem comes when I have to put those records in the Dojo Popup: The example shows that adding features to the Popup is as "simple" as using the setFeatures(features) method. This method receives either an array of Deferreds or an array of Features. In my case, I have both of them available.

I get the results like this and add it to the popup on map.infoWindow parameter:

mydeferred = featureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
var fset = relatedRecords[res.attributes['OBJECTID']];
var items = dojo.map(fset.features, function(feature) {
    feature.attributes.DateStart = Date(feature.attributes.DateStart).toLocaleString();
    feature.attributes.DateEnd = Date(feature.attributes.DateEnd).toLocaleString();
    return feature.attributes;


But, no matter if I pass to setFeatures a Deferred or a Feature array, that my output is the following one:

enter image description here

Does anyone detect the problem or the bug? I think that the problem might be related with the DOM structure of the features, because if you see the image attached, the function knows the size of the array of features, but does not display any of the related records. It is important to highlight that:

  • I had to manually add the geometry field to the features, maybe any other required parameter is missing and that is why the popup is showing nothing. Does it make sense?
  • At this moment, the info template function getTextContent() returns a string "Hello world", but it is not appearing in the popup.

Just to illustrate what I mean I have adapted ESRI's Query Related Records example to use Popup in this jsfiddle: http://jsfiddle.net/uBNAm/ I hope if you see this, you can understand fully what I mean. Just click red spots until a popup like the one above appears.

Maybe is it a bug? How should I proceed to report it?


Some time ago, I faced a similar situation. In my case, I even tried to pass to setFeatures the output of the queryRelatedFeatures, something like:

map.infoWindow.setFeatures(myFeatureLayer.queryRelatedFeatures(query, function(relatedRecords){...});

But it did not work either. I also tried the same with deferred and fset.features, without luck. Finally I had to show results in a panel, but I think that it is better to show them in a Popup.

In my opinion, DOM object returned by FeatureLayer::queryRelatedFeatures is different than the one returned, as in the examples, by FeatureLayer::selectFeatures although they both are Deferred. And this might have "unpredictable" consequences. I am attaching an image below:

enter image description here

First row is what a queryRelatedFeatures() returns. Second is what selectFeatures() returns. As you may see, they are completely different in the inside.

To conclude: results returned in the first case, are contained in a Feature Set, while results returned on the second case are contained in an Array of Features. I am not an expert in this ESRI ArcGIS JS-API, but I guess this might be a bug or a lack of functionality that could be fixed in a future release... Any ESRI developer around here to bring light? :-)

| improve this answer | |
  • 1
    Yes, I am starting to think that it might be a bug... I have added a link to jsFiddle (jsfiddle.net/uBNAm) in order you all can see the problem live. Let's see... If only D. Swingley ever could check this out! :-) – Irene Feb 27 '13 at 17:35

I have tried to solve this problem during the last week but with no results. However I found some kind of "workaround", using InfoWindows based on this example: The thing is querying the Related Records service using Featureayer.queryRelatedFeatures and check how many records returns the query to display a single feature or a set, just like in the example. It is not "cool" but at least it is functional.

Anyway, what I really would like was having the same functionality using the Popup. At the end of this thread, it is said that:

Ultimately, Esri support told me it couldn't be done using FeatureLayer::queryRelatedFeatures and gave it an enhancement/bug ID of NIM081851, but looking for it now I can't find it

I have tried to pass to the setFeatures function almost everything I could build up after this queryRelatedFeatures function: a deferred, [deferred], fset, fset.features, [fset.features], or a new array of features build by applying a .push() function while looping fset.features. And nothing. The more I can get is the image above.

I think it is a bit weird that this simple example can't be "translated" to a Popup...it must be something I am doing wrong, but still I am stuck in the same place. So I don't know what to do...

Any new ideas? Thanks to all!

| improve this answer | |

I have been trying to develop something similar and have had some success with a different approach. I use a query layer to create a one to many spatial view, and the default popup widget shows all related records. Here are details:

I have a featureclass "sewer pipes" and a table "inicdents", where multiple incidents are associated to a pipe by a fk relationship. I then created a query layer using a sql statement to return the desired records. A left join from pipes to incidents for example, creates a query layer with one feature for each incident. So if pipe 1120 has 3 inicdents in the incidents table, there are now three features stacked upon each other in the query layer. You can use almost any sql to build your query layer so its pretty flexible.

The js api sees this just like it was a featureclass in your map service, so the popup is really paging thru multiple features, but each feature corresponds to a record in your related table.

Not sure this is the best way to go. One drawback is that you can't enable attachments on a query layer. I need this feature so will have to extend the popup myself...

My app calls for editing the related records. Adding, deleting, modifying. I have this working with some code I have written to do rest operations to the incidents table which is a feature service.

| improve this answer | |
  • I understand the approach you mention, but I am wondering the following: This approach would create lots of duplicates in the output table, isn't it? Instead of having a "pointer" to the Incidents, you would have these records inside the Sewer Pipes Table and, therefore, there would be potentially many lines with the same ID. Did I get your point right? Thanks! – Irene Feb 28 '13 at 17:16
  • There would be no records added to the sewer pipes table. The query layer is much like a spatial view. It only reads the input tables and creates a new "view" of the data. This view is not stored on disk, it is generated on the fly in arcmap, and appears to the javascript api as a layer in the map service. The query layer would indeed have multiple lines if there are multiple related records in the incidents table. I think this is desireable, since the default popup will allow for paging through the records. – Zorba Conlen Mar 6 '13 at 18:13
  • @ZorbaConlen: you mention using a query layer. Do you mean you used the esri.layers.QueryDataSource? Do you have a code snippet that shows what worked for you and the SQL join you used? This sounds like a solution that could possibly be voted up if you provide some more information – maztaz Sep 5 '13 at 7:39

This seems related to ArcGIS JS API Relationship Queries.

I had the same issue, and I found that the relationship query wasn't finishing before the poup was displayed. I used setTimeout to solve my issue. The length of the timeout depends on how long it takes to query the related data.

setTimeout(function () { map.infoWindow.setFeatures([myDeferredResults]); }, 1000);

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.