Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion CoreService create component missing metadata

i got exception = {"Unable to find uuid:5708986b-390f-4728-b0c7-b49bd3d8f407:Metadata."}

schemaId = UpdatePubId(schemaId, containerId);
SchemaData schemaData = (SchemaData)client.Read(schemaId, null);
string xml = string.Format("<{0} xmlns=\"{1}\">{2}</{0}>", schemaData.RootElementName, schemaData.NamespaceUri, fields);

ComponentData componentData = new ComponentData
{
    Content = xml,
    ComponentType = ComponentType.Normal,
    Title = title,
    Schema = new LinkToSchemaData { IdRef = schemaId },
    LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = containerId } },
    Id = "tcm:0-0-0", 
    MetadataSchema = schemaData.MetadataSchema,
    Metadata = schemaData.Metadata
};

try
{
    componentData = client.Save(componentData, new ReadOptions()) as ComponentData;
    componentData = client.CheckIn(componentData.Id, new ReadOptions()) as ComponentData;
    message.Set("Component", title + ", successfully");
}
catch (Exception exception)
{
    message.Set("Component", exception.Message);
}

thanks Tridion experts

like image 592
Lucas Avatar asked Sep 27 '12 15:09

Lucas


1 Answers

You are on the correct path, but the error indicates that you have not provided the Metadata fields for the component that you are trying to create.

This line is incorrect:

Metadata = schemaData.Metadata

It should pretty much, like that one where you create the content fields:

Metadata = String.Format("<Metadata xmlns=\"{0}\">{1}</Metadata>",schemaData.NamespaceUri, "YOUR METADATA XML")
like image 118
Puntero Avatar answered Dec 16 '22 20:12

Puntero