Display related table info

2703
1
04-07-2014 11:50 AM
williamcarr
Occasional Contributor II
Greetings,

I'm attempting to view related tables from a query in either a info window, popup or attribute inspector. I have the relate set up and I can see the related table info in the dev. console, but I'm new to this (and clueless to boot).


 dojo.connect(map,"onClick",function(evt){
          var query = new esri.tasks.Query();
          query.geometry = pointToExtent(map,evt.mapPoint,10);
          var deferred = featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
          
          deferred(function (results) {       
           dojo.forEach(results, function(res){
            var relatedTopsQuery = new esri.tasks.RelationshipQuery();
            relatedTopsQuery.outFields = ["*"];
            relatedTopsQuery.relationshipId = 0;
            relatedTopsQuery.objectIds = [res.attributes['OBJECTID']];
            infoTemplate:template;
            
            
            mydeferred = featureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
             console.log("Related records: ", relatedRecords);
             
             var relationships = featureLayer.relationships;
             
dojo.forEach(relationships,function(relationship){
  console.log("name: " + relationship.name);
  console.log("id: " + relationship.id);
  console.log("relationship id: "   + relationship.relatedTableId);
  
});
             
             
             
             
             
             
              var fset = relatedRecords[res.attributes['OBJECTID']]; 
              var featureArray = [];
              
              dojo.forEach(fset.features, function(feature){
               featureArray.push(feature);              
              
              
              });
                          
             //map.infoWindow.setFeatures([relatedRecords.features]);
             map.infoWindow.setFeatures(relatedRecords.features);
             map.infoWindow.show(evt.mapPoint); 
             
              
            }); 
            
            // Add dojo.Deferred instead of relatedRecords or fset
            map.infoWindow.setFeatures([mydeferred]);
            map.infoWindow.show(evt.mapPoint);    
                     


I took this from a sample on fiddle, and I'm pretty sure I've done something wrong. Any ideas? Wisdom? Logic?
0 Kudos
1 Reply
MarlaKostuk
New Contributor III
Hi William,

I have attached some resources that I think will be helpful!

Formating Content in a Pop-up:
https://developers.arcgis.com/javascript/jssamples/widget_formatInfoWindow.html

Pop-up Charts:
https://developers.arcgis.com/javascript/jssamples/popup_chart.html

   var template = new PopupTemplate({
          title: "Boston Marathon 2013",
          description: "{Percent_Fi} of starters from {STATE_NAME} finished",
          fieldInfos: [{ //define field infos so we can specify an alias
            fieldName: "Number_Ent",
            label: "Entrants"
          },{
            fieldName: "Number_Sta",
            label: "Starters"
          },{
            fieldName: "Number_Fin",
            label: "Finishers"
          }],
          mediaInfos:[{ //define the bar chart
            caption: "Details",
            type:"barchart",
            value:{
              theme: "Dollar",
              fields:["Number_Ent","Number_Sta","Number_Fin"]
            }

          }]
        });


Happy Coding!

-Marla
0 Kudos