3

I'm trying to create keyword using core service API through PowerShell. I can do this for keywords at top-level under a category

$keyword = [Tridion.ContentManager.CoreService.Client.KeywordData]$client.GetDefaultData($itemTypeKeyword, $ParentWebdavUrl, $readoptions)
$keyword.Title = $Value
$keyword.Key = $Key
$keyword.Description = $Description

however, if I try to use the GetDefaultData when the $ParentWebdavUrl is a keyword instead of a category, it fails (specifically: Exception calling "GetDefaultData" with "3" argument(s): "Unexpected item type: Keyword."). So, I'm trying to do this, below, but can't seem to get the ParentKeywords to work. I've tried many permutations of creating the $parentLinks object to no avail.

$keyword = New-Object Tridion.ContentManager.CoreService.Client.KeywordData
$keyword.Title = $Value
$keyword.Key = $Key
$keyword.Description = $Description
$parentLink = New-Object Tridion.ContentManager.CoreService.Client.LinkToKeywordData
$parentLink.IdRef = $parent.Id
$parentLinks = [Tridion.ContentManager.CoreService.Client.LinkToKeywordData[]]([Tridion.ContentManager.CoreService.Client.LinkToKeywordData]$parentLink)
$keyword.ParentKeywords = $parentLinks
3

Parent item of your keyword remains the Category. You should set ParentKeywords property and pass your parent keyword there.

#here's what I was missing... need to set LocationInfo
$locInfo = New-Object Tridion.ContentManager.CoreService.Client.LocationInfo
$locInfo.OrganizationalItem = $parent.LocationInfo.OrganizationalItem
$locInfo.ContextRepository = $parent.LocationInfo.ContextRepository
$locInfo.Path = $parent.LocationInfo.Path
#apparently you don't have to set webdav url on it
#$locInfo.WebDavUrl = Get-EncodedWebdavUrl -WebdavUrl ($locInfo.Path + "\" + $Value + ".tkw")
#now associate to the keyword
$keyword.LocationInfo = $locInfo
| improve this answer | |
  • isn't that what I'm doing? I tested by creating a sub-keyword, doing ParentKeywords on it and inspecting the IdRef, which is the same value I'm setting in my $parentLink.IdRef = $parent.Id statement above. but the $parentLinks object doesn't seem to be constructed properly into an IEnumerable object that ParentKeywords method is expecting – Warner Soditus Jul 9 '14 at 12:59
  • If the code sample is everything you pass than you need to set LocationInfo.OrganizationalItem as well. – Andrey Marchuk Jul 9 '14 at 15:22
  • that's what I was missing!! awesome. thanks. problem solved! edited your answer to include the code I was missing. – Warner Soditus Jul 10 '14 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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