I'm setting up some basic functions for a Tridion 2013 SP1 EventSystem. The idea is simple, set the date on the metadata of a component when the metadata field is left empty. Now it seems that the event system thinks it's a new component and returns the following error.
An exception of type 'Tridion.ContentManager.ItemDoesNotExistException' occurred in Tridion.ContentManager.dll but was not handled in user code Additional information: The item tcm:3-4437-16-v0 does not exist.
The component uri of the component updating is: tcm:3-4437-16 so for some reason the eventsystem thinks it's a new component (-v0).
so here is my code:
EventSubscription
EventSystem.Subscribe<Component, SaveEventArgs>(ContentEvents.OnComponentSave, EventPhases.TransactionCommitted);
The Class Function
public static void OnComponentSave(Component component, SaveEventArgs args, EventPhases phase)
{
Log.Info(component, "OnComponentSave " + component.MetadataSchema.Title);
if (component.Metadata!=null)
{
var metadata = new ItemFields(component.Metadata, component.MetadataSchema);
var standardMeta = metadata.GetEmbeddedField("embed_standard_meta");
Log.Info(component, "OnComponentSave There is a metadata schema ");
if (standardMeta != null)
{
Log.Info(component, "OnComponentSave There is metadata");
if (standardMeta.GetDateValue("date_creation") == null || ((DateField)standardMeta["date_creation"]).Value == DateTime.MinValue)
{
((DateField)standardMeta["date_creation"]).Value = DateTime.Now;
component.Metadata = metadata.ToXml();
Log.Info(component, "OnComponentSave " + DateTime.Now);
}
}
}
}
Hope any one can point me in the right direction, it's kinda frustrating.