Recently I had a customer ask me for a rather simple feature – the ability to have Tridion folders and structure groups inherit the metadata schema and values from their parent. This would be only when creating new organizational items and obviously we want to show these default values on screen when editing.
Having spent the past few months completely buried in Anguilla/CME extensions, I obviously started thinking of implementing this by extending a whole bunch of Anguilla Commands and going all crazy on Javascript.
And then it hit me that perhaps, just perhaps, I was making it more complex than it has to. After all, it’s just setting a default value, right? The Tridion CM Core team must have thought about this.
And indeed they have. The solution is so simple I almost feel ashamed I didn’t find it before.
Event Registration:
EventSystem.Subscribe<OrganizationalItem, LoadEventArgs>(SetDefaultValues, EventPhases.Processed);
SetDefaultValues:
private void SetDefaultValues(OrganizationalItem subject, LoadEventArgs args, EventPhases phase)
{
   if (subject.Id.IsUriNull) //Is new
   {
       OrganizationalItem parent = subject.OrganizationalItem;
      if (parent.MetadataSchema != null && subject.MetadataSchema == null)
       {
           subject.MetadataSchema = parent.MetadataSchema;
           subject.Metadata = parent.Metadata;
       }
   }
}
Thanks for sharing Nuno, and welcome to tridiondeveloper.com
This opens up a whole new way of thinking for me
Sweet! I pointed a StackOverflow question on how automate that association to this post. Thanks, Nuno!
Good one. Thanks for sharing this, Nuno.
When I subscribe to the above event handler during ”TransactionCommitted’ ‘ phase of the load event, it gets called. Why is there a ‘TransactionCommitted’ phase during the load event?
@Premkumar, I assume this is for consistency more than anything else. Processed vs TransactionCommitted on a load event doesn’t indeed make much difference (maybe it does internally) but I think it would have been worse to NOT implement TransactionCommitted – again, for consistency across events.
Like this you can say that the LAST phase for a successful event is always TransactionCommitted, instead of having to go through the pain of explaining “except if this is a load event or a load application data event or etc…”
that’s awesome for copying all metadata from the parent. but, what happens when the business folks change their mind and only want SOME of the metadata copied…
trying to modify the solution to accommodate for that now.
Sounds like fun Warner, enjoy doing that one![:)](http://www.tridiondeveloper.com/wp-includes/images/smilies/simple-smile.png)
Pingback: Inherited Page Workflow Process Settings On Structure Groups | Coded Weapon