I need to add a Keyword based on its Keyword title using the Core Service. Please help me which function of Core Service I can use along with some sample code if possible as well.

I have a Keyword field name called "familyKeyword" Here I just need to insert a Keyword to field name family keyword using Core Service.

2 Answers 2

ComponentData ComponentContent = null;
var ComponentContent = client.Read("tcm:13-7666", new ReadOptions()) as ComponentData;
*//to read components*

var Keyword = client.Read("tcm:12-6867-10", new ReadOptions()) as KeywordData;
*//to read keywords*

string keywordTitle = Keyword.Title;
*//here u will get the title of the family keyoword*

client.Save(ComponentContent, new ReadOptions());
*//to save the component*

You can add a keyword, and set the keyword title, key and parent keywords using the following snippet:

KeywordData keyword = (KeywordData) client.GetDefaultData(ItemType.Keyword, categoryId, new ReadOptions());

keyword.Title = "Keyword Title";
keyword.Key = "Keyword Key";
keyword.ParentKeywords = new LinkToKeywordData[] { new LinkToKeywordData() { IdRef = parentKeywordID } };

keyword = client.Save(keyword, new ReadOptions()) as KeywordData;

Where categoryId is the TCM ID (or WebDAV) of the category, and parentKeywordID is the TCM ID (or WebDAV) of the parent keyword (unless it's a root keyword).

In general, you can use this approach to create other Tridion items like Components, Pages etc. You basically just call GetDefaultData(..) specifying the item type, update the content and then you save it to store it in the CM database.

Hope this helps.

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.