I would like to update an embedded Component field value when I check in my Page using TOM.NET Event System but the Component field value update is not happening.
I am not sure what am doing wrong here.
ItemFields componentFields = new ItemFields(component.Content, component.Schema);
if (componentFields.Contains("videoDetail"))
{
EmbeddedSchemaField videoDetail = componentFields["videoDetail"] as EmbeddedSchemaField;
if (videoDetail != null)
{
component.CheckOut();
IList<ItemFields> videoDetailValues = videoDetail.Values;
foreach (ItemFields innerFields in videoDetailValues)
{
if (innerFields.Contains("videoTitle"))
{
Headertext = innerFields["videoTitle"] as TextField;
}
if (innerFields.Contains("childPageName"))
{
XhtmlField childPageName = (XhtmlField)innerFields["childPageName"];
childPageName.Value = component.Title;
}
}
}
}
component.Content = componentFields.ToXml();
component.Save(true);
innerFields
- can you write the debug value of theinnerFields.ToXml()
before you try to save?