Reputation: 355
In Sitecore when a non admin user selects lock and edit option of an Item we are creating a new version and change it's workflow state to the previous version's one. This is done using item locked event. Also when user click save button in new version, if it is in a certain workflow state(state X) it should transfer to another state(state Y). We have done this using OnItemSaving event. But there is a problem in this approach, in item locked event handler when new version's workflow state is changed using following code
using (new Sitecore.SecurityModel.SecurityDisabler())
{
latestVersion.Editing.BeginEdit();
latestVersion.Fields["__workflow state"].Value = previousVersion.Fields["__workflow state"].Value;
latestVersion.Editing.EndEdit();
}
it would fire item saving event Instantaneously because of EndEdit() function. So if the item was changed to state X it would immediately be changed to state Y, something we don't want to happen.
What we need to do is distinctly identify user clicking Save button from general item saving. Is this a possible thing to do?
Upvotes: 2
Views: 668
Reputation: 27132
You can add your own processor to saveUI
pipeline instead of using OnItemSaving
, e.g. after the processor:
<saveUI>
...
...
<processor mode="on" type="Sitecore.Pipelines.Save.Save, Sitecore.Kernel" />
As John West explains in blog post Access field values in saveUI pipeline processors with Sitecore
Sitecore only invokes the saveUI pipeline when users save items, not when you use APIs to update items.
So it looks like this is exactly what you want to achieve.
Upvotes: 4