Edit Operation Fails On Second Use

1591
5
02-06-2017 07:45 PM
ChristopherStayte
New Contributor

I am trying to take the selection the use has and change a value in the field from 'null' to 1. This seems easy with inspector but I run it once and it works fine. I run it the second time and i get an edit operation has failed. I am unsure why this is happening.

public void Update(int status, Layer featureLayer, string editName)
{
QueuedTask.Run(async () => {
try
{
var basicfeaturelayer = _selectedLayer as BasicFeatureLayer;
var selection = basicfeaturelayer.GetSelection();
var oidset = selection.GetObjectIDs();


var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector(true);
insp.Load(basicfeaturelayer, oidset);
insp[InpsectorFieldName] = 1;
await insp.ApplyAsync();

basicfeaturelayer.ClearSelection();
} catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}

});
}

0 Kudos
5 Replies
by Anonymous User
Not applicable

Christopher,

Behind the scenes, Inspector.ApplyAsync creates an edit operation, passes the inspector to the modify method and executes it. Since you clear the selection on the first run the oidset will be empty on the second, causing the edit operation to fail as it doesn't distinguish between an empty recordset and other failures.

To avoid the error you can check the count on the oidset before applying.

0 Kudos
ChristopherStayte
New Contributor

Thanks for the feedback. I check the user selection before each pass. I am using this tool so that a user can click on an item and mark it as "done" or 1. That way they can pan and move on to the next one and select it and mark it as "done". There is a selection on the second time and for some strange reason if I save before I run the method it works the second time. In arcobjects I am able to accomplish this using a cursor. I am wondering if the implementation just isn't there yet on pro. 

0 Kudos
by Anonymous User
Not applicable

The implementation you have should be fine. Here's the code I'm using:

    protected override void OnClick()
    {
      QueuedTask.Run(async () => {
        try
        {
          var featLayer = MapView.Active.Map.FindLayers("Ranger stations").First() as BasicFeatureLayer;
          var selection = featLayer.GetSelection();
          var oidset = selection.GetObjectIDs();

          var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
          insp.Load(featLayer, oidset);
          insp["TEST"] = 1;
          await insp.ApplyAsync();
          featLayer.ClearSelection();
        }
        catch (Exception ex)
        {
          MessageBox.Show("Error: " + ex.Message);
        }
      });
    }

Working after a save is curious. What's your data source? Shapefiles, filegdb, enterprise, feature service etc?

To date ive just been testing on a filegdb. I can select a point, run the code, select another point etc.

Are these newly created features in your edit session or have previously existed?

0 Kudos
ChrisStayte
New Contributor II

I am editing from a file geodatabase. These are newly created features. I have also tested on existing features. 

Here is my view model.

 InspectorSettingsViewModel.cs · GitHub 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Christopher,

 I tried this sample from the community samples:

 https://github.com/esri/arcgis-pro-sdk-community-samples/tree/master/Editing/ConstructionTool

and changed the code by commenting out the "Use edit operations ..." region in AttributeButton.cs and instead uncommented the "#if OrUseThis" section following the above region.  I think this closely reflects the workflow you describe above.  I then used the community sample dataset and ran the sample  and was able to execute the update multiple times.  Maybe you can see differences between the sample and your implementation.  Also I used Pro 1.4 for this.
Attribute columns are updated

0 Kudos