Using related records offline

06-08-2016 12:34 AM
New Contributor II

is there any way to use "Related Record Samples" with "Offline Feature Editing" ?

I have tried to implement but so far did not been able to success.  The reason is all the data is been loaded as AGSFeatureTableLayer in Offline sample, and the related records works as AGSFeatureLayer in Swift, is there any way to convert the data from Table data to AGSFeatureLayer ?

Best Regards.

Tags (2)
5 Replies
New Contributor II

No answer ?

0 Kudos
New Contributor II

Have found some similar example, But still couldn't figure out.

for info: AGSMapServiceTableInfo in weakSelf.gdbTask.featureServiceInfo.tableInfos {

    var url: NSURL = weakSelf.gdbTask.URL.URLByAppendingPathComponent("\(info.tableId)")

    var fl: AGSFeatureLayer = AGSFeatureLayer.featureServiceLayerWithURL(url, mode: AGSFeatureLayerModeOnDemand)

weakSelf.mapView.addMapLayer(fl, withName:

fl.outFields = ["*"]

    fl.delegate = weakSelf

    fl.queryDelegate = weakSelf

    fl.editingDelegate = weakSelf


With this piece of code i though i can convert it AGSFeatureLayer so i can use queryRelatedFeatures

please help how can i use the related records with offline sample.

Divesh Goyal​, Suganya BaskaranYue Wu


0 Kudos
by Esri Regular Contributor
Esri Regular Contributor

Hi John,

In order to use Offline function to sync tables, you need to make sure that your relatedTable is also enable the sync function from ArcGIS Server side, otherwise it is not possible to sync or query those tables in offline mode. Prepare data for offline use—Documentation (10.3 and 10.3.1) | ArcGIS for Server

Once the data schema is correct, you need to make sure when you download the offline gdb to loop through all the table's iD

with an ArcGIS Server map or feature service by checking this Class 10.2.5: AGSMapServiceTableInfo Class Reference

Here is a snippet code that you generate the gdb generate parameters:

    AGSGDBGenerateParameters* syncParams = [[AGSGDBGenerateParameters alloc] initWithExtent:self.mapView.visibleAreaEnvelope layerIDs:tableIds];
    syncParams.syncModel = AGSGDBSyncModelPerLayer;
    syncParams.outSpatialReference = [AGSSpatialReference spatialReferenceWithWKID:102100];
    syncParams.queries = [self createLayerQueries];

You can use AGSGDBLayerQuery to control the download gdb with certain layers and tables, you can take a look about this class 10.2.5: AGSGDBLayerQuery Class Reference, for example:

- (NSArray*)createLayerQueries
// RelatedTable Query
    NSString* relatedTableQueryWhere = [NSString stringWithFormat:@"some generic query syntax"];
    AGSGDBLayerQuery* relatedTableQuery = [[AGSGDBLayerQuery alloc] init];
    customerQuery.layerID = kCustomerServiceIndex;
    customerQuery.option = AGSGDBQueryOptionUseFilter;
    customerQuery.useGeometry = NO;
    customerQuery.whereClause = relatedTableQueryWhere;
    return query;
0 Kudos
New Contributor II

Thank Yue Wu,

Finally Someone answered.

I m developing my application in swift, Do you have the code in swift ?

I have enabled the Sync in Arcgis Server. Even i have updated to 10.3.1.

But my issue starts at when i try to display related records like in the sample. It needs AGSFeatureLayer .queryRelatedFeatures function.

Is there any way to cast the data from AGSFeatureTableLayer ?  As your sample is all i need but i just need to run in Offline Editing Sample.

Even if you share a sample code with working Offline Editing sample will do.

Thank you again.

0 Kudos
Esri Regular Contributor

When you use a local geodatabase, you display features using a AGSFeatureTableLayer. This AGSFeatureTableLayer works with AGSFeatureTable which corresponds to individual tables & layers in the geodatabase. If you downcast from AGSFeatureTable to AGSGDBFeatureTable, you'll notice that there is a method `queryRelatedFeaturesWithParameters()` which allows you to get related records from another layer or table. This is equivalent to the online version `AGSFeatureLayer.queryRelatedFeatures()`.

Note, for the related query to work offline, you must ensure that the local geodatabase does indeed include the related data. You do this by setting up the AGSGDBGenerateParameters correctly. The param contains an array of AGSGDBLayerQuery objects which decides what data to include for each layer/table in the geodatabase. If you have a layer A related to layer B, then you must include an AGSGDBLayerQuery object for each layer so that their data is included in the generated geodatabase.