Deleting Keywords in Tridion

One of the search terms entered to find this website reads “sample code to delete keywords in tridion”, which I do have a vb script for.

To run the script here’s what you need to do:

  1. Create a new page, component or template building block
  2. Paste in the code below
  3. Change the value of the variable strCategoryID to the TCM ID of your category
  4. Preview code to execute it

[%

Dim strCategoryID : strCategoryID = "tcm:21-88-512"

' Call the function passing in the categoryID
DeleteKeywordsFromCategory(strCategoryID)

Function DeleteKeywordsFromCategory(categoryID)

' Get the Category object - TCM must be valid!
Dim objCategory : Set objCategory = GetTomObject(categoryID)

For each objKeyword in objCategory.GetItems(1024) ' 1024 is the item type for keyword
Writeout "Deleting keyword: " + objKeyword.Title & "<br />"
objKeyword.Delete
Next

End Function
%]

Once ran, you should see something like this:

Obviously such a basic example could be performed using the GUI, but this could certainly be customised to delete a certain keyword from a category, rename a keyword, display a list of keywords etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>