Select to view content in your preferred language

How to use AGSRelatedQueryParameters with AGSRelationshipInfo?

1141
5
Jump to solution
05-29-2018 07:49 AM
MuruganandhamKuppan1
Regular Contributor

I would like to know how to use 'AGSRelatedQueryParameters' with 'AGSRelationshipInfo'. Give me an example. I guess 'AGSRelatedQueryParameters' is the replacement for 'AGSRelationshipQuery'. Am i right?

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor
5 Replies
Nicholas-Furness
Esri Regular Contributor

Hi Muruganandham Kuppan,

You can find a sample here: arcgis-runtime-samples-ios/RelatedFeaturesViewController.swift

Hope that helps.

Nick.

MuruganandhamKuppan1
Regular Contributor

Hi Nicholas Furness‌,

This returns an empty array. But the `AGSRelationshipInfo`  logs the related table id correctly. FYI, i can get the related features in  iOS Runtime SDK v 10.2.

AGSServiceFeatureTable * featureTable = (AGSServiceFeatureTable*)data.graphic.featureTable;

 AGSRelationshipInfo * rInfo = featureTable.layerInfo.relationshipInfos.firstObject;

    

    AGSRelatedQueryParameters * find = [AGSRelatedQueryParameters relatedQueryParametersWithRelationshipInfo:rInfo];

    find.orderByFields = @[[[AGSOrderBy alloc] initWithFieldName:rInfo.keyField sortOrder:AGSSortOrderDescending]];

    

    NSString * whereClause = [NSString stringWithFormat:@"""%@ = '%lld'""",rInfo.keyField,data.objectID];

    [find setWhereClause:whereClause];

    

    [featureTable queryRelatedFeaturesForFeature😞AGSArcGISFeature*)data.graphic parameters:find completion:^(NSArray<AGSRelatedFeatureQueryResult *> * _Nullable results, NSError * _Nullable error) {

        

        if(error)

        {

        }

        else

        {

            

            NSLog(@"result-assets :: %@",results);        

         }

 }];

Did i missed any thing here?

Regards,

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi,

Depending on what data.graphic is, you may need an additional step.

If data.graphic is an AGSArcGISFeature instance which you created, added, and then stored with applyEdits (as opposed to an object you got back from a query), then before you do further operations on it, you should call AGSArcGISFeature.refreshObjectID().

In more detail: For any feature you get with a query, it'll already have the data store's ID populated, but if you create the feature, there is no ID until it's stored (when working against a local geodatabse/shapefile, that happens when you call addFeature, or when working against an AGSServiceFeatureTable, when you call applyEdits). Since it's bad for us to assume we can update your Objective-C objects without telling you, we don't set the ID automatically as part of the add/apply operation, so if you want to continue using the same reference to the AGSArcGISFeature for future writes (e.g adding attachments or relating records), call AGSArcGISFeature.refreshObjectID().

In your case above, try calling refreshObjectID() on data.graphic before querying for related features.

Let me know if that helps.

Nick.

0 Kudos
MuruganandhamKuppan1
Regular Contributor

Yes, your reply worked for me. This is regarding listing related features. I have followed the following class arcgis-runtime-samples-ios/ListRelatedFeaturesVC.swift at ea83939a56101ef82f17ff6eecb1b2faa716d720 ·...  to fetch the related features. I tried to add related table in mapview as like in example. i got the following error:

ArcGIS Runtime Error Ocurred. Set a breakpoint on C++ exceptions to see the original callstack and context for this error:  Error Domain=com.esri.arcgis.runtime.error Code=24 "Object already owned." UserInfo={NSLocalizedFailureReason=Already owned., NSLocalizedDescription=Object already owned., Additional Message=Already owned.}

I didn't get any clear idea about this. How can i add related table object to map.tables.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

It's really hard to determine without more info or sample code, but in general that error means that something else is already tied to that table. The table may already be part of the map.tables collection or a layer in your map might be using it.

If you still really need to duplicate the layer, you could call copy() on it and add that reference to the map but I'd suggest you double-check that you're not unwittingly duplicating things.

0 Kudos