0

I need to push array of the object IDs to RelationshipQuery's object using executeForIds that generates the array. I also used executeRelationshipQuery that executes the query. I don't not why, but executeForIds executes after the executeRelationshipQuery, so objectIds array in RelationshipQuery is empty. Can anyone advise me how to push all objectIds to array? Everything works fine when I push the array to RelationshipQuery manually without executeForIds (queryRel.objectIds = [1,2,3,...]). Here is my code:

 var queryTask = new QueryTask({
              url: "http://xxx/ags/rest/services/xxx/xxx/FeatureServer/1"
          });
          var query = new Query();
          query.outFields = ["*"];

const queryRel = new RelationshipQuery({
              outFields: ["*"],
              relationshipId: 0,
              returnGeometry: true
});

 queryTask.executeForIds({  
                  where: "id <> ''"
              }).then(function pokus(results) {
                  queryRel.objectIds = results; 
                      alert(queryRel.objectIds);                                      
              });

 queryTask.executeRelationshipQuery(queryRel).then(function (results) {                
                  console.log("queryTask results", results);
              });
1

By default, all the query task in the ArcGIS JavaScript API are async hence they will not follow the order that you are calling them in.

You will need to chain the promises.

You can follow the documentation on: https://developers.arcgis.com/javascript/latest/guide/working-with-promises/

Also, there is a sample: https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=chaining-promises

All you need to do is chain the promises and extract all the object ID's from the response.

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.