3

How do I apply the async/await feature to this code? I need to wait for the reltionshipQuery and forEach to finish before I return contentSpecies.

 contentSpecies = function(value, key, data) {
 var contentSpecies = [];
 objectID = data.OBJECTID;
 var queryTask = new QueryTask({
 url: "https://webmaps.com/MapServer/1"
 });
 var relationQuery = new RelationshipQuery({
 objectIds: [objectID],
 outFields: ["Species", "Notes", "Status"],
 returnGeometry: true,
 relationshipId: 0
 });
 queryTask.executeRelationshipQuery(relationQuery)
 .then(function(rslts) {
 var features = rslts[objectID].features;
 features.forEach(function(ftr) {
 var t = ftr.attributes;
 var species = t.Species;
 contentSpecies += "<span class='bold' title='Species'><b>Species: </b></span>" + species + "<br/>";
 var notes = t.Notes;
 contentSpecies += "<span class='bold' title='Notese'><b>Notes: </b></span>" + notes + "<br/>";
 var status = t.Status;
 contentSpecies += "<span class='bold' title='Status'><b>Status: </b></span>" + status + "<br/>";
 });
 //return contentSpecies;
 })
 return contentSpecies
 }
asked Jun 22, 2018 at 21:17

2 Answers 2

1
contentSpecies = async function(value, key, data) {
 try {
 ...
 let rslts = await queryTask.executeRelationshipQuery(relationQuery);
 var features = rslts[objectID].features;
 features.forEach(function(ftr) {
 ...
 } catch(e) {
 console.error(e);
 }
}
answered Jun 23, 2018 at 12:00
1
  • it is not executing. can't even get a console log to work. Commented Jun 25, 2018 at 19:18
0
async function xxx(){ 
 var results = await queryTask.executeRelationshipQuery(relationQuery)
}

It works for me - see Using async await in ArcGIS JavaScript API

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Nov 6, 2024 at 17:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.