1
votes

I'd like to get the parent value in its child item.

Parent and child are using same template (I mean it is the same standard values) and if parent updates the one of field value in content (not in __standard values), the same field in child item also changes.

I don't know exactly if I can use "Insert Rule" in Sitecore. Can I know how to use "Insert Rule"?

3

3 Answers

1
votes

I'm not sure if this is the best place to use Insert Rules.

However you can use item:created event instead:

<event name="item:created">
  <handler type="YourNameSpace.UpdateFieldEventHandler, YourAssembly" method="OnItemCreated" />
</event>
public class UpdateFieldEventHandler
{
    public void OnItemCreated(object sender, EventArgs args)
    {
        using (new SecurityDisabler())
        {
            ItemCreatedEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;
            if (arg != null && arg.Item.TemplateName == "Your Template"
                && arg.Item.Parent.TemplateName == "Your Template")
            {
                arg.Item.Editing.BeginEdit();
                arg.Item["Your Field Name"] = arg.Item.Parent["Your Field Name"];
                arg.Item.Editing.EndEdit();
            }
        }
    }
}

Code is not tested but in worst case it should point you in the right direction.

2
votes

You can update the child item when saving the parent item. Some options for hooking into the saving of the parent item are described here:

http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx

To update the child item(s), you'll need to do something like this:

foreach (var child in parent.GetChildren())
{
    child.Editing.BeginEdit();
    child.Fields["My Field"].Value = parent.Fields["My Field"].Value;
    child.Editing.EndEdit();
}
0
votes

When saving you will know the current item and you can check for child items of the same template exists and if so update those at that time.

I'm not sure whether you need to know parent item at that point but if u need you can do a item.parent on the current item being saved.