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 />";
}
Jay,
Move line 40 inside your executeRelationshipQuery function handler (the "then" function).
my console log?
i added sampleTypes and still no results
queryTask.executeRelationshipQuery(relationQuery).then(function(rslts, sampleTypes){
Jay,
No that is not what I meant. Your code is asynchronous thus you have to wait for the realtionship query to return before you attempt to set the contents of your popup. The way your code in your original post is the popups content gets set using:
content += "<span class='bold' title='Types of sample collected'><b>Sample Types: </b></span>" + sampleTypes + "<br />";
Before the query ever completes. You you have to wait for the query to return before you set that line or show the popup.
I see, thanks Robert!