Select to view content in your preferred language

Getting an error when ending the editing workflow in the Editor Widget

202
2
Jump to solution
03-14-2025 06:05 AM
MarkSmith
Occasional Contributor

I’m having a problem handling leaving the Editor Widget when a feature is selected.  I’ve built an API that allows users to switch to ‘edit mode’.  When this happens the selected Feature Layer is added to the map and the Editor Widget (already added) automatically detects the new Feature Layer and presents the user with all the Widget tools.  This works great.

The problem is that users can choose to move away from the Editor Widget at any point, effectively giving up on what they were doing and returning to use the API for some other purpose, in other words exiting editing mode.  I’ve got most of this handled successfully using myEditor.cancelWorkflow() .  If they decide to discard their editing when drawing a new feature for example, then cancelWorkflow() works perfectly.  I’m detecting what the user was currently doing with myEditor.viewModel.state.  For example, when they are drawing a new feature, the state is “creating-features”, and I can then use cancelWorkflow() to discard what they were doing and follow that up with removing the Feature Layer that had been added to the map - works great.  However, the problem occurs when they select an existing feature for editing its shape or attributes, in this instance the viewModel state is “editing-attributes”, and when I try to do cancelWorkflow() I get the error “view:no-layerview-for-layer”.

I’ve tried to do my best to understand the API reference for a solution, but to no avail.  Interestingly, the cancelling of the edit session using cancelWorkflow() appears to work when the state is “editing-attributes” in that the selected feature is de-selected and the sketching graphics are removed (e.g. the points highlighting the vertices), but the error mentioned above is thrown and I’d like to do things properly and not get this error message.

I hope that’s clear?  Can anyone please suggest a solution, or the correct way to cancel the current editing process the user is doing?  I don’t want to destroy the Editor Widget completely, I want it to remain because the user might want to do more editing, I just need to end their current workflow without it throwing the error I see for the “editing-attributes” state.

Thank you.

0 Kudos
1 Solution

Accepted Solutions
Edvinas_S
Esri Contributor

Here is a modified Editor sample: Editor cancel workflow sample

It doesn't throw errors. Maybe the error occurs because of your custom code? If you add and then remove a layer manually, maybe you should check if it exists before removing?

View solution in original post

2 Replies
Edvinas_S
Esri Contributor

Here is a modified Editor sample: Editor cancel workflow sample

It doesn't throw errors. Maybe the error occurs because of your custom code? If you add and then remove a layer manually, maybe you should check if it exists before removing?

MarkSmith
Occasional Contributor

Hi, thanks for responding.  You were correct.  Whilst my code had been written to preform actions in the correct order, they weren't in fact completing in that order, resulting in the Feature Service being removed before the cancelWorkflow().  So thanks for the hint, it's led me to find the problem.