Offline editing related table

5286
5
Jump to solution
12-02-2014 10:14 AM
ColinCole
New Contributor II

Hi,

I've successfully implemented offline editing for a feature service in my app, but I'm having trouble replicating the offline functionality for a related table. Do I have to treat the related table as a completely separate service and replicate all of the sync objects ( AGSGDBSyncTask, AGSGDBGeodatabase, AGSGDBFeatureServiceTable, etc.) for this service as well?

Any starting point or Esri example code would be be appreciated!

Thanks,

Colin

0 Kudos
1 Solution

Accepted Solutions
SuganyaBaskaran1
Esri Contributor

In general, a related records table is treated an offline feature table inside a geodatabase.

Let's say you have a service with a feature service, and a related table

Screen Shot 2014-12-02 at 11.50.20 AM.png

1. Creating and downloading the geodatabase: You treat them two separate layers in the service. For instance, your generate params might look like below where layerID 0 is your spatial layer, and layerID 1 being related table. You only need one AGSGDBSyncTask object, and get back one AGSGDBGeodatabase object

AGSGDBGenerateParameters *generateParams =[[AGSGDBGenerateParameters alloc] initWithExtent:_replicaExtent layerIDs:@[@0,@1]];

2. Once you get AGSGDBGeodatabase object, you would have two tables from which you create AGSGDBFeatureTable objects

3. Querying related records: You can to use AGSRelationshipQuery (similar to online workflow) which will be called on the (spatial) table.

[spatialTable queryRelatedFeaturesWithParameters:relationshipQuery completion:^(NSDictionary *results, NSError *error) {

  /*Enumerate results dictionary. Keys are Object IDs of spatial table, and iterate the cursor. For instance,

  AGSGDBQueryResultCursor *cursor = [results objectForKey:[NSNumber numberWithUnsignedInteger:572]];

  AGSGDBFeature *feature = cursor.currentFeature; //Related record feature

  */

  }];

4. Editing:

Once you have the related records for a feature through querying, you can display them in a popup, edit and save. An online example for presenting popups is shown in this sample here, and you can have a similar workflow.

(In your question, I think you mentioned AGSGDBFeatureServiceTable instead of AGSGDBFeatureTable. AGSGDBFeatureServiceTable is not used for offline sync workflow )

Hope this helps,

Suganya

View solution in original post

0 Kudos
5 Replies
SuganyaBaskaran1
Esri Contributor

In general, a related records table is treated an offline feature table inside a geodatabase.

Let's say you have a service with a feature service, and a related table

Screen Shot 2014-12-02 at 11.50.20 AM.png

1. Creating and downloading the geodatabase: You treat them two separate layers in the service. For instance, your generate params might look like below where layerID 0 is your spatial layer, and layerID 1 being related table. You only need one AGSGDBSyncTask object, and get back one AGSGDBGeodatabase object

AGSGDBGenerateParameters *generateParams =[[AGSGDBGenerateParameters alloc] initWithExtent:_replicaExtent layerIDs:@[@0,@1]];

2. Once you get AGSGDBGeodatabase object, you would have two tables from which you create AGSGDBFeatureTable objects

3. Querying related records: You can to use AGSRelationshipQuery (similar to online workflow) which will be called on the (spatial) table.

[spatialTable queryRelatedFeaturesWithParameters:relationshipQuery completion:^(NSDictionary *results, NSError *error) {

  /*Enumerate results dictionary. Keys are Object IDs of spatial table, and iterate the cursor. For instance,

  AGSGDBQueryResultCursor *cursor = [results objectForKey:[NSNumber numberWithUnsignedInteger:572]];

  AGSGDBFeature *feature = cursor.currentFeature; //Related record feature

  */

  }];

4. Editing:

Once you have the related records for a feature through querying, you can display them in a popup, edit and save. An online example for presenting popups is shown in this sample here, and you can have a similar workflow.

(In your question, I think you mentioned AGSGDBFeatureServiceTable instead of AGSGDBFeatureTable. AGSGDBFeatureServiceTable is not used for offline sync workflow )

Hope this helps,

Suganya

0 Kudos
ColinCole
New Contributor II

Great, that gave me alot of clarity for the offline workflow of related tables. Thanks!

Now for online....

I've created a AGSGDBFeatureServiceTable for my related table layer, the same way I created it for the feature service layer. The feature layer service loads fine, however the the related table layer is not loading the 'templates' property. Any idea why that could be? Do I create a separate object apart from the AGSGDBFeatuerServiceTable when initializing a Table layer?

I've attached a screenshot of my code where the AGSGDBFeatureServiceTables are created:

Screen Shot 2014-12-02 at 4.50.02 PM.png

0 Kudos
SuganyaBaskaran1
Esri Contributor

Colin,

I believe this is related to the ‘Invalid JSON’ error here. Let us know if you have more questions

Thanks,

Suganya

0 Kudos
ColinCole
New Contributor II

Yes it is - thanks!

0 Kudos
ColinCole
New Contributor II

Suganya Baskaran,

Is -queryRelatedFeaturesWithParameters() the only method that can be used when querying a non-spatial offline table? It seems that the AGSRelationshipQuery class assumes that we use the OBJECTID as the link between the feature table and related table, which my application does not.

In my application, we allow the user to specify any field they want as the link. For example, 'HydrantID' could be the common linking field between our feature table and related table.

As always, we have used the AGSQuery class for querying related records, using a custom 'where' clause. Unless I'm mistaken, this custom 'where' clause does not exist in the AGSRelationshipQuery object. This is the problem.

Thanks,

Colin

0 Kudos