While trying to build a workaround for the lack of related table/feature support in 100.0.0 I found that I'm not able to set any GUID field values. The goal is to set the foreign key value for a feature to the GlobalID value of its related feature in the geodatabase in code. My relationships are all 1-M in the geodatabase.
On the coding side it works just fine until I perform the following:
var saveResults = await table.SaveChangesAsync();
Where table is a ServiceFeatureTable.
In my many iterations, I found that the following do not work:
I get an ArcGISWebException error "Unable to complete operation" with the detailed message "Setting of value for DeviceID failed." for all non-null values. Null/unassigned values just fail because GUIDs cannot be null.
I'm using the ArcGIS Server 10.5.0 (build 6491), Windows Server 2012 R2, and SQL Server 2014 on the backend, all with the latest updates.
This is the final piece of the puzzle to complete my project. Any help would be greatly appreciated.
Here is some sample code that works for me in v100.
feature is an ArcGISFeature.
After this, you can then use FeatureTable.AddFeatureAsync() and ServiceFeatureTable.ApplyEditsAsync() as required.
Hope this helps.
//Create a new Guid and get the field from the table
var guid = Guid.NewGuid ();
var guidFld = feature.FeatureTable.Fields.FirstOrDefault (f => f.Name == fieldName.Trim());
//Make sure the field is found, editable, and then set the value
if (guidFld != null) {
if (guidFld.IsEditable)
feature.SetAttributeValue (fieldName.Trim (), guid);
}
Thanks for the Field.IsEditable. I didn't have that, and it's definitely something that should have been in my code from the start. It unfortunately didn't fix my problem.
After further investigation (after added the Field.IsEditable) I found these 2 rather helpful elements in the feature service logs:
<Msg time='2017-06-29T13:28:23,800' type='SEVERE' code='17000' target='GravelCheckers/GravelAppOnly_GravelCheckers.MapServer' methodName='FSGraphicFeature::PopulateBuffer' machine='GISDMZ' process='8704' thread='904' user='anonymous' >Error: A general error when something is wrong with a Field. [DeviceID].</Msg>
<Msg time='2017-06-29T13:28:23,800' type='SEVERE' code='17000' target='GravelCheckers/GravelAppOnly_GravelCheckers.MapServer' methodName='GraphicFeatureLayer.Add' machine='GISDMZ' process='8704' thread='904' user='anonymous' >Edit for the Feature in Layer: 9 is not applied.</Msg>
Any idea what this means? DeviceID is the foreign key field that I'm trying to populate, and I don't understand the second message either.
Haven't ever seen those error messages.
Couple of things:
- Did you try the code using a new guid?
- Can you confirm the field type for DeviceID is an esriFieldTypeGUID?
- Did you publish the services with ArcMap or ArcGIS Pro? I've seen some posting on different results based on the method the services were published.
- Are you working online or offline, or both? If only online, do you get the same, or different (possibly more helpful) message when working offline.
That's all that comes to mind right now.
In order:
I've not used Pro, but I have seen this forum that others have been having issues. Using ArcMap is what I used and I've been able to get that code to work and successfully store a Guid.
So when you are trying to save the GUID, is it directly to the online service, or to a local SQLite database?
Have you tried to edit one of these features in AGOL or Portal? Wonder if that would work/fail and/or give you a better message.
I'm not able to see the DeviceID foreign key field on the table that uses it in AGOL. Setting the value in ArcGIS Pro (the UI is extremely confusing) worked well enough. The data synced down to my test device perfectly.
You've given me a lot to think about. It'll keep working on this and post an update once I get it to work. Thanks
Hi,
The newly released v100.1 API now includes support for working with related tables: Relate features—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers.
Cheers
Mike