ebrightc

Related Records Query

Discussion created by ebrightc on May 15, 2012
Latest reply on May 18, 2012 by njarecha-esristaff
I am having trouble implementing AGSRelationshipQuery, I get a successful response, but the data returned id not what I expect and I am not sure if I am setting up my query the correct way. What I am trying to do is query related records from a point feature class (through a map service) that has a relationship set up with a table.
Here is code: (the names of the server and services have been changed to protect the innocent, and unfortunately, this server is not public so i can't point anybody to it)

- (void)mapView:(AGSMapView *)mapView didClickCalloutAccessoryButtonForGraphic:(AGSGraphic *)graphic {

    self.queryTask = [AGSQueryTask queryTaskWithURL:[NSURL URLWithString:@"http://<myServer>/arcgis/rest/services/<myFolder>/<myService>/MapServer/0"]];
    self.queryTask.delegate = self;
   
    self.relQuery = [AGSRelationshipQuery relationshipQuery];
    self.relQuery.objectIds = [NSArray arrayWithObject:[graphic.attributes objectForKey:@"OBJECTID"]];
    self.relQuery.outFields = [NSArray arrayWithObject :@"*"];
    self.relQuery.relationshipId = 0;

    [self.queryTask executeWithRelationshipQuery:self.relQuery];
{

- (void) queryTask:(AGSQueryTask *)queryTask operation:(NSOperation*)op didExecuteWithRelatedFeatures:(NSDictionary *)relatedFeatures {

   NSLog(@"relatedFeatures: %@", relatedFeatures);

}


The response I get back from the NSLog on related Features is:

relatedFeatures: (
    "AGSFeatureSet: display name: (null)
\ngeometry type: esriGeometryPoint
\nnum features: 1
\nspatial reference: (null)"
)


I have confirmed the parameters in my query are valid using the rest/services web page, and there I get a json object that has the data I expect. But I am not sure what to make of the response I am getting through the iOS API.
I have also tested the a regular http request using the direct URL for the REST query, and I do get back the proper response,

    NSString *relatedQueryString = @"http://<myServer>/ArcGIS/rest/services/<myFolder>/<myService>/MapServer/0/queryRelatedRecords?objectIds=1&relationshipId=0&definitionExpression=&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=*&f=pjson";
    NSError *theError = nil; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:relatedQueryString]];
    NSURLResponse *theResponse = [[NSURLResponse alloc] init];
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
    NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *jsonDict = [string AGSJSONValue];



so I am figuring I am just not setting up the related request correctly.
Chris

Outcomes