Open patadata opened 6 years ago
You are not the only one @patadata, I am facing the same issue. And I am very much aligned to your suggestions (commands mentioned) as well for creating new Sub Terms.
Is it really not possible to create sub terms using the PnP? I have been pulling my hair out trying to find the correct format... then I found this post. I'll have to check the source for an answer, it has to be there.
@Lucho1970 nope, it does not work :(
I was able to get around this problem. Using the New-PnpTerm command, it will return a term object. Just call CreateTerm from that object to create a child.
$ctx = Get-PnPContext
$newTerm = New-PnpTerm -Name "Pastel" -TermSet "Colours" -TermGroup "Company Colours" -Id "GUID"
$childTerm = $newTerm.CreateTerm("Blue", 1033, "New Term Guid")
$ctx.Load($newTerm) $ctx.ExecuteQuery()
Not technically all PnP powershell, but it allowed me to get around the limitation.
Good call!
I still don't like the mix in PnP-Powershell between actual PS and JSOM, it's a bit confusing, but as in this case, it could come in handy!
Thanx!
If I have some time (Yeah right!!) I'll try to create a pull request in the PnP library and add this functionality. It really isn't too hard.
I was able to get around this problem. Using the New-PnpTerm command, it will return a term object. Just call CreateTerm from that object to create a child.
First you must get the Context
$ctx = Get-PnPContext
Create the new Parent Term
$newTerm = New-PnpTerm -Name "Pastel" -TermSet "Colours" -TermGroup "Company Colours" -Id "GUID"
Use that parent to create the child term
$childTerm = $newTerm.CreateTerm("Blue", 1033, "New Term Guid")
Have the context do the work
$ctx.Load($newTerm) $ctx.ExecuteQuery()
Not technically all PnP powershell, but it allowed me to get around the limitation.
This approach didnt work form me, pnp-powershell complained that method was not available. As a workaround, I first retrieved the parent term, then created the new term, and then leverage the method "move", as described in the below example:
$ctx = Get-PnPContext
$parent_term = Get-PnPTerm -Identity "[desired_parent_termset" -TermSet "[termset_being_used]" -TermGroup "[term_group_being_used]" -Recursive -IncludeChildTerms
$new_term=New-PnPTerm -Name "[my_new_term]" -TermSet "[termset_being_used]" -TermGroup "[term_group_being_used]" -LCID "1033" -LocalCustomProperties @{_Sys_Nav_SimpleLinkUrl = "[a custom property example" }
$new_term.Move($parent_term)
$ctx.Load($new_term)
$ctx.ExecuteQuery()
easy ;-)
Hey, I just crossed this issue by accident because I'm also currently testing around with PnP Terms. In my opinion, there is a PowerShell cmdlet to create subterms: Import-PnPTaxonomy
Interesting, and how do you move an existing subterm move a certain parent term to another parent term? Would you mind providing a code example? thanks in advance
Yet another way to create a sub term:
$parentTerm = Get-PnPTerm -TermGroup "GroupName" -TermSet "TermSet" -Identity "Parent Term Name" -IncludeChildTerms -Recursive
$parentTerm.CreateTerm("New child", 1033, (New-Guid))
Invoke-PnPQuery
@holylander - to move an existing term you could do this:
$termToMove = Get-PnPTerm -TermGroup "GroupName" -TermSet "TermSet" -Identity "Term Name" -IncludeChildTerms -Recursive
$newParent = Get-PnPTerm -TermGroup "GroupName" -TermSet "TermSet" -Identity "NewParentName" -IncludeChildTerms -Recursive
$termToMove.Move($newParent)
Invoke-PnPQuery
Reporting an Issue or Missing Feature
Missing feature
I can not understand how the ability to create sub terms has been left out!? Is it just me and all the organisations I have been working with as a consultant that has these demands?
My suggestion to how to implement this, syntax wise, would be:
New-PnPTerm -TermSet "Departments" -TermGroup "Corporate" -Name "Finance" -ParentTermId ab2af486-e097-4b4a-9444-527b251f1f8d
New-PnPTerm -Name "Finance" -ParentTermPath "Corporate|Departments|Economics"
I am running the latest version of both the 2016 and the online cmdlets and I would love to have this as a feature in these.