How do I pass multiple ObjectIds as Number[] delimited list to execute a relationship query

1320
3
Jump to solution
02-27-2018 01:09 PM
AnikaHirt
New Contributor II

I'm trying to make a relationship query with the returned object ids from a previous query but having trouble passing multiple IDs 

var query = new Query(); 
query.returnGeometry = false; 
query.outFields = ["OBJECTID"]; 
query.where = requestTerm; 

myQueryTask.execute(query, function(results) { 

    if (results.features.length > 0) { 
        var ids = []; 
        for (var i = 0; i < results.features.length; i++){ 
            ids(Number(results.features[i].attributes.OBJECTID)); 
        } 

        query = new RelationshipQuery(); 
        query.returnGeometry = false; 
        query.outFields = ["OBJECTID"]; 
        query.objectIds = [ids]; 
        query.relationshipId = 1; 
        myQueryTask.executeRelationshipQuery(query, function(set) { 
            // .... 
        } 
    } 
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I also tried to set the IDs with

ids(new Number(results.features[i].attributes.OBJECTID));

 as well as directly, but nothing seems to work.

query.objectIds = [304,305,306];// and casted

query.objectIds = [Number(304),Number(305)];

but nothing seems to right. 

Any suggestions or is there an example with multiple ObjectIds?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Anika,

  You should do:

ids.push(results.features[i].attributes.OBJECTID);

Better yet do a executeforids on your first querytask.

https://developers.arcgis.com/javascript/3/jsapi/querytask-amd.html#executeforids 

The result will be a array of object id numbers.

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Anika,

  You should do:

ids.push(results.features[i].attributes.OBJECTID);

Better yet do a executeforids on your first querytask.

https://developers.arcgis.com/javascript/3/jsapi/querytask-amd.html#executeforids 

The result will be a array of object id numbers.

AnikaHirt
New Contributor II

Thanks. I just realised my mistake was somewhere else but the executeforids option is much nicer so I changed it to that.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Great,

   Don't forget to mark this question as answered.

0 Kudos