Hi,
I'm trying to add some field values programmatically after feature is created. Code is working fine for feature class but not working with feature layer created from FeatureService.
After creating feature I assigned field value and can see feature is getting added in feature layer attribute table in Arcpro 2.7 but doesn't sync online. I manually saved all edit's but still data is not appearing in feature service. After refresh or zoom-in/out feature gets cleated from Arcpro attribute table also.
Here is my code:
{
var mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Contains("Map"));
if (mapProjItem == null)
return;
QueuedTask.Run(() =>
{
var theMap = mapProjItem.GetMap();
IEnumerable<FeatureLayer> featLayer = theMap.GetLayersAsFlattenedList().OfType<FeatureLayer>();
foreach (FeatureLayer item in featLayer)
{
var layerTable = item.GetTable();
_rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);
}
}
private Guid _currentRowChangedGuid = Guid.Empty;
private void onRowCreateEvent(RowChangedEventArgs args)
{
if (_currentRowChangedGuid == args.Guid)
return;
var row = args.Row;
row["fieldname"] = "Some Value";
_currentRowChangedGuid = args.Guid;
row.Store();
_currentRowChangedGuid = Guid.Empty;
}
Is there anything additional I need to do to save feature service edits?
Any help would be appreciated.
-Prashant
Solved! Go to Solution.
In a previous post (now deleted) I incorrectly assumed an OnChangeRow event was needed to make an attribute change stick. I was wrong. I now see that EditOperation.Modify works within the OnCreateRow event. This is similar to the way ArcObjects requires editoperations.
private void Test4()
{
var mapProjItem = Project.Current.GetItems<MapProjectItem>()
.FirstOrDefault(item => item.Name.Contains("Map"));
if (mapProjItem == null)
return; // (no "Map" found)
QueuedTask.Run(() =>
{
var featTable = mapProjItem.GetMap()
.GetLayersAsFlattenedList()
.OfType<FeatureLayer>()
.Select(fLayer => fLayer.GetTable())
.FirstOrDefault(t => t.GetDataConnection() is CIMStandardDataConnection);
if (featTable == null)
return; // (no featureservice layer found)
var token1 = RowCreatedEvent.Subscribe(ea =>
{
// this doesn't stick ...
//ea.Row["DisplayName"] = DateTime.Now.Ticks;
// but this does (same way arcobjects needs an editoperation)...
ea.Operation.Modify(ea.Row, "DisplayName", DateTime.Now.Ticks);
}, featTable);
});
}
I wonder if what you're seeing is related to this issue:
Perhaps "We'll work on these" means a bug tracking number was assigned to it?
In a previous post (now deleted) I incorrectly assumed an OnChangeRow event was needed to make an attribute change stick. I was wrong. I now see that EditOperation.Modify works within the OnCreateRow event. This is similar to the way ArcObjects requires editoperations.
private void Test4()
{
var mapProjItem = Project.Current.GetItems<MapProjectItem>()
.FirstOrDefault(item => item.Name.Contains("Map"));
if (mapProjItem == null)
return; // (no "Map" found)
QueuedTask.Run(() =>
{
var featTable = mapProjItem.GetMap()
.GetLayersAsFlattenedList()
.OfType<FeatureLayer>()
.Select(fLayer => fLayer.GetTable())
.FirstOrDefault(t => t.GetDataConnection() is CIMStandardDataConnection);
if (featTable == null)
return; // (no featureservice layer found)
var token1 = RowCreatedEvent.Subscribe(ea =>
{
// this doesn't stick ...
//ea.Row["DisplayName"] = DateTime.Now.Ticks;
// but this does (same way arcobjects needs an editoperation)...
ea.Operation.Modify(ea.Row, "DisplayName", DateTime.Now.Ticks);
}, featTable);
});
}