7

I am trying to copy the Keyword value to a Metadata field value using the SDL Tridion Core Service. I am able to run my console app successfully without any error but I don't see the Metadata field value getting copied.

Below is my code. Please advise.

enter image description here

KeywordData currentKeyword = (KeywordData)client.TryCheckOut(keywordUri, readOptions);
string translatedTitle = currentKeyword.Title;

if (currentKeyword.MetadataSchema.IdRef != "tcm:0-0-0")
{
    SchemaFieldsData schemaFieldsData = 
       client.ReadSchemaFields(currentKeyword.MetadataSchema.IdRef, true, readOptions);
    SingleLineTextFieldDefinitionData test = new SingleLineTextFieldDefinitionData();
    test = (SingleLineTextFieldDefinitionData)schemaFieldsData.MetadataFields[0];
    test.DefaultValue = translatedTitle;
    currentKeyword = (KeywordData)client.Save(currentKeyword, readOptions); 
}

2 Answers 2

8

What you need to do is to populate the Metadata property available in your Keyword. It should be something like this.

keyword.Metadata = "<Metadata xmlns=\"[your namespace]\"><translated_value>Myvalue</translated_value></Metadata>";
client.Save(keyword, readOptions);
1
  • If this worked for you, you should accept Eric's answer Commented Sep 29, 2013 at 17:38
2

Apart from Eric's answer which should solve your question (if you agree then by all means please accept that answer), I'll add a few remarks based on the information you give which hopefully will clarify it even more.

First thing which struck me was that you are using the Core Service to set the title from the Keyword to its Metadata. You could subscribe to the Keyword Save event and use an Event Handler to do that too. Which means that code could be automatically executed. I'm not sure if that could be useful for you since I don't know your full requirements.

Secondly, you start your Core Service code with a TryCheckOut() call, which isn't really needed. Since the Core Service is service oriented, you don't have to explicitly check out before a save. This only is required when using the TOM.NET in an event handler or a template. So if you need to use the Core Service, then you only have to focus on on the code to set your value and calling Save.

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.