1

I try to CRUD components in an ASP.NET MVC 4 project using Tridion Core Service

First, I read a configuration component :

var publicationData = client.Read("tcm:180-278202", new ReadOptions()) as ComponentData;

var componentData = new ComponentData
{
    Content = publicationData.Content,
    ComponentType = ComponentType.Normal,
    Title = "random title",
    Schema = new LinkToSchemaData { IdRef = "tcm:179-277976-8" },
    LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItem { IdRef = "tcm:179-109377-2" }},
    Id = "tcm:0-0-0"
};

client.Save(componentData, new ReadOptions());

I get an error message on the Client.Save with the following message :

(translated from dutch) Unexpected stem? element : Content. Expected : uuid:1d939ee2-29e5-4a94-b378-5c6420d6d46f:Configuration

The uuid is the same except that there is no ":Configuration" at the end

Every suggestion is welcome.

2 Answers 2

5

The schema has (at least) one mandatory field named "Configuration", and your code is not setting any field values, so the content fails XML validation.

You need to add content to your componentData.Content and make sure it's valid according to schema before you can save it. Check if publicationData.Content includes the "Configuration" field?

1
  • Actually the schema changed during the time I wasn't on this project, that's why I searched a tag 'configuration' that didn't exist, I checked and now it's working, thanks
    – Giu Do
    Commented Jul 16, 2013 at 12:17
4

Rather than building the component manually, a more robust approach is to request the default information from Tridion using

client.GetDefaultData(ITEM_TYPE, CONTAINER_TCM_ID);

This is create the component based on the container, populating all mandatory fields with the default values.

So in your case something like

var publicationData = client.Read("tcm:180-278202", new ReadOptions()) as ComponentData;

var componentData = client.GetDefaultData(ItemType.Component, "tcm:179-109377-2") as ComponentData; 

componentData.Content = publicationData.Content; //with configuration field set
componentData.Title = "Title";
componentData.Schema = new LinkToSchemaData { IdRef = "tcm:179-277976-8" }

client.Save(componentData, new ReadOptions());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.