Repeat EditOperations fail with "Row contains a bad value"

378
2
03-15-2023 02:38 PM
GrayBohnen
New Contributor II

I'm trying to create new features in a Utility Network feature service by using a series of  EditOperation.CreateEx() calls. The first time I run the process, each feature is created exactly as expected, but if I try to run the same process again, I get a failed result with the error "ERROR: Unable to complete operation., The row contains a bad value." The code below is fundamentally what I'm running, though pared down a bit for simplicity. I have every reason to believe the fields I'm creating are correct. I'm checking subtypes, domain values, length, type, etc. 

A couple other things are fishy about the first edit operation too. It doesn't create any new entries on the undo stack, regardless of setting long or short to the EditOperationType, and when I set SelectNewFeatures they are not selected when the operation finishes. 

This makes me believe something is failing at the end of the first operation, and it is not closing a process or exiting gracefully, but I don't know what to change to fix that. Is there a smoking gun that I'm overlooking? 

I also found this help article, which doesn't illuminate the matter very much.

 

public async Task RegenerateSelectedRecord()
{

CancelableProgressorSource progressorSource = new CancelableProgressorSource("Restoring features...", "Cancelling restore...", true);

await QueuedTask.Run(
() =>


{


EditOperation editOperation = new EditOperation();
editOperation.Name = "Restoring deleted features";
editOperation.SelectNewFeatures = true;

// loop through the feature data to create

foreach (var newObject in this.featuresToRestore)

{

// get the field values

var bufferValues = newObject.GetValues();

// get the table

var table = newObject.GetTable();

RowToken rowToken = editOperation.CreateEx(table, bufferValues);

editOperation.Execute();

// the above succeeds on each row the first time it's called.
editOperation = editOperation.CreateChainedOperation();

// do something with the row token to make sure it was created

}

// I do more stuff with the edit operation, removing this does not change the result

// I add relationships and associations to the restored row here, they are created as expected the first time

// later down the road, execute the last step if anything got missed

if (!editOperation.IsEmpty)
{


editOperation.Execute();


}


}, progressorSource.Progressor);


}

Tags (2)
0 Kudos
2 Replies
GrayBohnen
New Contributor II

Just to be crystal clear: The first chain of editoperations works, and I'm usually doing 1-5 methods with it. The 2nd time I call the exact same code, it fails on the first editoperation method. 

I get the same error if I run all of the operations through EditOperation.Callback() instead of the methods.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

You cant assign CreateChainedOperation result to the same variable editOperation. Each assigning destroys your previous operation. So you need new variable editOperation1. You can't execute twice the same operation.

And I can't see your chained operation execution.

Another one thing that CreateChainedOperation must be created after main operation is executed.

Look here:

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9507.html 

0 Kudos