AnsweredAssumed Answered

relationQuery inside popupTemplate content function is not populating popup

Question asked by JJhill on Jan 25, 2018
Latest reply on Jan 29, 2018 by JJhill

But it returns my console logs correctly.

 

My content function is executing before the code to run the query on the related table finishes. Therefore returning blank values.

 

What is the best way to time this?

if (att.OBJECTID != null) {

                  var finalArray = [];
                  var objectID = att.OBJECTID;
                  var queryTask = new QueryTask({
                     url: "https://services.arcgis.com/blah/FeatureServer/0"
                  });

                  relationQuery = new RelationshipQuery({
                     objectIds: [objectID],
                     outFields: ["TYPE"],
                     relationshipId: 0
                   });
                   coreType = "";
                   myArray = [];
                   sampleTypes = "";
                   queryTask.executeRelationshipQuery(relationQuery).then(function(rslts){

                     var features = rslts[objectID].features;
                     features.forEach(function (ftr){
                       var t = ftr.attributes;
                       coreType = t.TYPE;
                       myArray.push(coreType);
                     });

                     function removeDuplicates(myArray){
                       let unique_array = []
                       for(let i = 0;i < myArray.length; i++){
                         if(unique_array.indexOf(myArray[i]) == -1){
                           unique_array.push(myArray[i])
                         }
                       }
                       return unique_array
                     }
                     console.log(myArray);
                     console.log(removeDuplicates(myArray));
                     finalArray = removeDuplicates(myArray);
                     //sampleTypes = "";
                     sampleTypes = finalArray.join(", ");
                     console.log(sampleTypes);
                  });

                  content += "<span class='bold' title='Types of sample collected'><b>Sample Types: </b></span>" + sampleTypes + "<br />";
                }

Outcomes