Tridion: errors when setting up page metadata schema in event system

This is on the Tridion 2011 SP1.

I use the save component event in the Tridion event system to create the corresponding page and associate some metadata with this page. When I specify a scheme, I get event logs that indicate that the UUID of the scheme cannot be found.

The UUID that is in the error is for the metadata scheme that I want to use, and I also use the local TcmUri for the metadata scheme. At the moment, I am a little lost.

Below is .NET and the resulting error:

the code

public static TcmUri CreatePage(TcmUri parentSgId, Component component, TcmUri componentTemplateUri, TcmUri metaDataSchemaUri = null) { Logging.Debug("Attempting to create page in " + parentSgId.ToString()); Page page = new Page(component.Session, parentSgId); page.Title = component.Title; page.FileName = component.Title; // Add a metadata schema if (metaDataSchemaUri != null) { TcmUri localMetaDataSchemaUri = TransformTcmUri(metaDataSchemaUri, parentSgId); page.MetadataSchema = (Schema)page.Session.GetObject(localMetaDataSchemaUri); } // Add the CP TcmUri localComponentUri = Helpers.TransformTcmUri(component.Id, parentSgId); TcmUri localComponentTemplateUri = Helpers.TransformTcmUri(componentTemplateUri, parentSgId); page.ComponentPresentations.Add(new ComponentPresentation(new Component(localComponentUri, component.Session), new ComponentTemplate(localComponentTemplateUri, component.Session))); try { page.Save(true); Logging.Debug("Created page successfully " + page.Id.ToString()); return page.Id; } catch (Exception ex) { throw new Exception(ex.Message); } } 

Error

 Unable to find uuid:C42EE4FC-D2A2-49F5-92C7-BF6DCB014343:Metadata. Component: Tridion.ContentManager Errorcode: 0 User: EMAKINA\MTSUser StackTrace Information Details: at Bair.Tridion.Events.Utilities.Helpers.CreatePage(TcmUri parentSgId, Component component, TcmUri componentTemplateUri, TcmUri metaDataSchemaUri) [...] 
+6
source share
3 answers

The problem Quirijin talked about was that I did not set the metadata for the page before trying to save it. The working code is below.

Configure page metadata

 if (metaDataSchemaUri != null) { Helpers.SetPageMetaData(metaDataSchemaUri, parentSgId, component, ref page); } 

Method SetPageMetaData p>

  protected static void SetPageMetaData(TcmUri metaDataSchemaUri, TcmUri parentSgId, Component component, ref Page page) { TcmUri localMetaDataSchemaUri = TransformTcmUri(metaDataSchemaUri, parentSgId); page.MetadataSchema = (Schema)page.Session.GetObject(localMetaDataSchemaUri); ItemFields metaFields = new ItemFields((Schema)page.Session.GetObject(localMetaDataSchemaUri)); Logging.Debug("Schema title: " + page.MetadataSchema.Title); // Set the page metadata TextField pageTitle = (TextField)metaFields["pagetitle"]; pageTitle.Value = "The page title"; [...] KeywordField showbreadcrumb = (KeywordField)metaFields["showbreadcrumb"]; showbreadcrumb.Value = new Keyword(TransformTcmUri(new TcmUri("tcm:134-12018-1024"), parentSgId), page.Session); [...] } page.Metadata = metaFields.ToXml(); Logging.Debug("Page metadata set"); } 
+6
source

I was able to reproduce your error on my own image. After some investigation, I was able to find out what the problem is. The error "Unable to find uuid: C42EE4FC-D2A2-49F5-92C7-BF6DCB014343: Metadata" means that the schema setup is fine, but it cannot find this element in the XML page. You must explicitly install .Metadata! Here is what I did to successfully save the page and add a metadata schema:

  private void SetMetadata(Page page, SaveEventArgs eventArgs, EventPhases phases) { try { Schema schema = (Schema)page.Session.GetObject("tcm:3-5806-8"); if (page.MetadataSchema == null) { page.MetadataSchema = schema; ItemFields metadata = new ItemFields(schema); TextField showInNav = (TextField)metadata["showinmenu"]; showInNav.Value = "No"; page.Metadata = metadata.ToXml(); SetPageMetadata.LogMessage("Set Page Metadata"); } } catch (Exception e) { SetPageMetadata.LogMessage("An error occurred while rsetting the Page metadata:\n" + e.Message); } } 
+5
source

Have you checked the circuit for any problems? It contains this namespace value (uuid: C42EE4FC-D2A2-49F5-92C7-BF6DCB014343: Metadata). Sometimes it’s worth clearing your browser’s cache and restarting CME to make sure you are looking at the latest diagram.

+1
source

Source: https://habr.com/ru/post/909641/


All Articles