I am writing an event which is executed on page save and I need to validate one of the Page metadata fields. If it is blank then I have to set that value from the Structure Group Metadata field,
public void Validate(RepositoryLocalObject page)
{
try
{
var metadata = new ItemFields(page.Metadata, page.MetadataSchema);
var categorisation = ((EmbeddedSchemaField)metadata["categorisation"]).Value;
if (categorisation == null)
{
var item = page.OrganizationalItem;
if (item.Metadata != null && item.MetadataSchema != null)
{
var parentMetaData = new ItemFields(item.Metadata, item.MetadataSchema);
if (parentMetaData != null)
{
EmbeddedSchemaField pageFields = (EmbeddedSchemaField)metadata["categorisation"];
var parenetCategorisation = ((EmbeddedSchemaField)parentMetaData["categorisation"]).Value;
pageFields.Value = parenetCategorisation;
if (parenetCategorisation != null)
{
page.Metadata["categorisation"].InnerText = pageFields.ToString();
}
}
}
}
}
catch(Exception ex)
{
throw new Exception("Not all section fields have been set " + ex.Message + " " + ex.StackTrace);
}
}
I am getting the error on the below line,
page.Metadata["categorisation"].InnerText = pageFields.ToString();
Could anyone suggest that how to set this value to page metadata fields?