views:

32

answers:

4

Hi,

Got an annoying issue.

When a user edits a field on an item, we use a OnSavingItem event handler to create some new items elsewhere in the background as it were.

Problem is the item the users edited the field of gets redirected to the item we invisible created in the background.

We want it to stay where it is... Any ideas?

thanks

A: 

Are you using the

<event name="item:saved">

Handler? If so, don't forget that this event is fired on all the new items you create as well, potentially triggering a recursive event loop.

Mark Cassidy
Yep we are, but we only execute our code if the item is of a specific template.
danswain
A: 

This answer came from the SiteCore forum ... credit goes to John West

I think you could use the item:saving event or the saveUI pipeline. Use the event if you need to handle changes that occur through APIs, or use the pipeline if you only need to handle changes that occur through the user interface.

You could also consider adding the logic to the field itself.

John West Sitecore Blog

danswain
A: 

If you want to disable the transfer to the item you've just created you could also consider implementing the following code:

// Before we copy the item we put notifications on to make sure we won't be transfered to the newly created item                        
Sitecore.Client.Site.Notifications.Disabled = true;

// Your action comes here

Sitecore.Client.Site.Notifications.Disabled = false;
Younes
That's the exact code I wrote :)
danswain
A: 

item:saved is much heavier than a processor within the saveUI pipeline. For example, item:saved is triggered during publishing which is not what you really want. I always recommend handling such customizations either on the pipeline or workflow action level.

Alex Shyba