Select to view content in your preferred language

Debugging EditOperation

787
2
Jump to solution
07-19-2022 02:18 PM
BerndtNording
Regular Contributor

Is there a way to get more information when an EditOperation fails using the SDK? I have an addin that populates a field in a layer with values and it works fine the first time, but fails when I run it again. Further investigation showed that the edit operation works when the existing values are <null>, but fails if the existing values are not null. But more generally, i would like to get a reason when an EditOperation fails.

An abbreviated part of my code:

EditOperation assignIDEditOp = new EditOperation();
              assignIDEditOp.Name = "assignIDEditOp";
              assignIDEditOp.SelectModifiedFeatures = false;
              assignIDEditOp.SelectNewFeatures = false;

                strID += (j + 1).ToString(fmt);
                pInsp = new Inspector(true);
                pInsp.Load(pLay, pOID);
                pInsp["ID"] = strID;
                assignIDEditOp.Modify(pInsp);

              isOK = assignIDEditOp.Execute();
              if (!isOK)
              {
                MessageBox.Show(assignIDEditOp.ErrorMessage);
              }
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Unfortunately, there is only a general error message for this type of failure.   We are still checking if this is a potential bug.  What i see in my test add-in is that i can set the value only if the value is different.  For example: if your ID field already has a value of '5' i can't perform the update by writing a new value of '5', instead that would cause the 'operation failed' error.  However, i can write a value of '6'.  In my sample snippet below i write a time string that changes every minute, but i can't write the new value unless it's different.  This is a work around you can use since IsEmpty is true if no values have changed:

if (!assignIDEditOp.IsEmpty)
{
  // write the new value ....
  var isOK = assignIDEditOp.Execute();
 ...
}
The sample snippet is for 2.9,

 

protected override void OnClick()
{
    var pLay = MapView.Active?.Map.GetLayersAsFlattenedList()
        .OfType<FeatureLayer>().Where(r => r.Name == "TestPoints")
        .FirstOrDefault();
    if (pLay == null) return;
    var updateId = 5;
    QueuedTask.Run(() =>
    {
        EditOperation assignIDEditOp = new EditOperation
        {
            Name = "assignIDEditOp",
            SelectModifiedFeatures = false,
            SelectNewFeatures = false
        };

        var strID = $@"ID={DateTime.Now.ToShortTimeString()}";
        var pInsp = new Inspector(true);  // 3.0 doesn't need isFeatureEditing: true anymore
        pInsp.Load(pLay, 5);
        {
            pInsp["TheString"] = strID;
            assignIDEditOp.Modify(pInsp);
            if (!assignIDEditOp.IsEmpty)
            {
                var isOK = assignIDEditOp.Execute();
                if (!isOK)
                {
                    MessageBox.Show(assignIDEditOp.ErrorMessage);
                }
            }
        }
    });
}

 

It turns out that there's a previous post about this issue:

https://community.esri.com/t5/arcgis-pro-sdk-questions/editoperation-failed/m-p/1178371#M8204

 

 

     

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Unfortunately, there is only a general error message for this type of failure.   We are still checking if this is a potential bug.  What i see in my test add-in is that i can set the value only if the value is different.  For example: if your ID field already has a value of '5' i can't perform the update by writing a new value of '5', instead that would cause the 'operation failed' error.  However, i can write a value of '6'.  In my sample snippet below i write a time string that changes every minute, but i can't write the new value unless it's different.  This is a work around you can use since IsEmpty is true if no values have changed:

if (!assignIDEditOp.IsEmpty)
{
  // write the new value ....
  var isOK = assignIDEditOp.Execute();
 ...
}
The sample snippet is for 2.9,

 

protected override void OnClick()
{
    var pLay = MapView.Active?.Map.GetLayersAsFlattenedList()
        .OfType<FeatureLayer>().Where(r => r.Name == "TestPoints")
        .FirstOrDefault();
    if (pLay == null) return;
    var updateId = 5;
    QueuedTask.Run(() =>
    {
        EditOperation assignIDEditOp = new EditOperation
        {
            Name = "assignIDEditOp",
            SelectModifiedFeatures = false,
            SelectNewFeatures = false
        };

        var strID = $@"ID={DateTime.Now.ToShortTimeString()}";
        var pInsp = new Inspector(true);  // 3.0 doesn't need isFeatureEditing: true anymore
        pInsp.Load(pLay, 5);
        {
            pInsp["TheString"] = strID;
            assignIDEditOp.Modify(pInsp);
            if (!assignIDEditOp.IsEmpty)
            {
                var isOK = assignIDEditOp.Execute();
                if (!isOK)
                {
                    MessageBox.Show(assignIDEditOp.ErrorMessage);
                }
            }
        }
    });
}

 

It turns out that there's a previous post about this issue:

https://community.esri.com/t5/arcgis-pro-sdk-questions/editoperation-failed/m-p/1178371#M8204

 

 

     

0 Kudos
BerndtNording
Regular Contributor

Thank you for the reply, Wolf. My search did not come up with the post you linked; It gave me an understanding of why this was happening. Seems like a bug only in so far as the EditOperation's ErrorMessage is misleading. Not doing anything when it is not given anything to do isn't really a failure.