1

I have a cloned item.

I want to know which item is it cloned from (what is the source item of the clone).

How can I do that in Sitecore itself or using codebehind c#?

2 Answers 2

0

Sitecore supports an event subscription where you define an event name and the code to process the event.

With elevated access, open up the ShowConfig.aspx.

The following depicts an event subscription for item:copied. When this event is raised, the event handler defined will process it.

<events>
    <event name="item:copied">
        <handler type="Sitecore.Links.ItemEventHandler, Sitecore.Kernel" method="OnItemCopied" resolve="true"/>
    </event>
</events>
protected internal void OnItemCopied(object sender, EventArgs args)
{
    Item item = Event.ExtractParameter<Item>(args, 1);
    //Do something with the item.
}

If you continue searching for "item:copied" in a Dotnet reflection tool (like ILSpy, DotPeek, JustDecompile) you'll find a method containing this code:

Event.RaiseEvent("item:copied", new object[] { args.Source, args.Copy });

When considering item clones, there is an event called item:cloneAdded that you can subscribe to. There is another answer that helps you find all clones for a given item.

How to find all the cloned items?

2
  • i just want to know the already cloned item which item is cloned from not the opposite scenario
    – Sara
    Sep 22, 2022 at 20:29
  • Can you add the clarification to your question? Sep 22, 2022 at 20:37
0

Sitecore stores information about the source of a clone in __Source Item and Source fields.

sitecore clone source

You can get the value in c# code using

var sourceField = item.Fields[Sitecore.FieldIDs.Source];
var sourceItemField = item.Fields[Sitecore.FieldIDs.SourceItem];

__Source item field is shared - it keeps the source item reference.

Source field is versioned - it keeps source versions for every language separately.

They both store string values like:

Source: sitecore://master/{2163CB8F-3CF1-4183-A53A-2B9ED850646C}?lang=de&ver=1 _Source Item: sitecore://master/{2163CB8F-3CF1-4183-A53A-2B9ED850646C}

2
  • it seems good , but those fields are empty and not set , do you have any idea why not set ?
    – Sara
    Sep 26, 2022 at 11:55
  • That means that it is not a clone. I guess you just copied that item instead of cloning
    – Marek Musielak
    Sep 27, 2022 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.