Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore item:created vs item:added

What is the difference between the events item:created vs item:added? When does each event get hit?

like image 554
M.R. Avatar asked Nov 07 '12 22:11

M.R.


People also ask

What is an item in Sitecore?

Items are the basic building blocks of your Sitecore website. Items are the basic building blocks of your website. An item can represent any kind of information that makes up a webpage, for example, a piece of text, a media file, a layout, and so on.

What is event handlers and how we can create a event handlers in Sitecore?

Events in Sitecore are similar to events in other systems: handlers subscribe to the event, and when the event is raised, the handlers are called. Many system events in Sitecore are exposed as events that you can subscribe to. It is also possible to add your own events to the system.


2 Answers

Looking at the code of the Sitecore.Data.Events.ItemAddedDelegate you may read that this delegate is deprecated and you should use ItemCreatedDelegate instead. From my tests:

  1. Creating new item - both item:added and item:created are executed
  2. Cloning item - both item:added and item:created are executed
  3. Duplicating item - item:added is NOT executed, only item:created is executed

    namespace Sitecore.Data.Events
    {
        [Obsolete("Use the ItemCreatedDelegate event instead.")]
        public delegate void ItemAddedDelegate(object sender, ItemAddedEventArgs args);
    }
    

So in general, always use item:created

like image 63
Marek Musielak Avatar answered Sep 22 '22 20:09

Marek Musielak


The item:added and item:created events seem similar, but Sitecore only fires item:added when a user creates an item through the UI, but it fires fires item:created when code creates items through APIs. Use item:added if you only need to trap manual item additions.

Reference: Taken from John West's blog post

http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2011/05/all-about-events-in-the-sitecore-aspnet-cms

like image 24
Jason Bert Avatar answered Sep 23 '22 20:09

Jason Bert