3

I'm having trouble with SharePoint CSOM getting child terms using Term object's GetTerms method. In PowerShell using PnP PowerShell I do this:

PS C:\> $term = Get-PnPTerm -Identity "Regions" -TermSet "Location" -TermGroup "Common"
PS C:\> $childTerms = $term.GetTerms(100)
PS C:\> $term.Context.Load($childTerms)
PS C:\> $term.Context.ExecuteQuery()

Exception calling "ExecuteQuery" with "0" argument(s): "Specified argument was out of the range of valid values.
Parameter name: lcid"
At line:1 char:1
+ $term.Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServerException

I get the same error when I do this inside ASP.NET MVC application representing remote web in my SharePoint provider-hosted add-in.

  • Are you trying to get all terms inside the TermSet or a Term? – Asad Refai Nov 9 '17 at 13:28
1

You can refer the code of PnP GetTerm function @ GitHub you will get better understanding of the command.

Update : Solution to your problem

I am having PnP's October 2017 Intermediate Release 2. They way you load the term object is causing problem. Follow below code it should work.

$term = Get-PnPTerm -Identity "Regions" -TermSet "Location" -TermGroup "Common"
$ctx = $term.Context
$ctx.Load($term.Terms)
$ctx.ExecuteQuery()
$term.Terms ## This should list all child terms
  • I need to get all child terms under particular term in a term set, not all the terms from that term set – Rustam Nov 9 '17 at 13:46
  • @Rustam once you get all terms, can you not manipulate the terms and retrieve your desired ones. – Asad Refai Nov 9 '17 at 14:58
  • I'm interested in how to use the API method I asked about. – Rustam Nov 9 '17 at 16:28
  • @Rustam Check the updated answer, it should work. – Asad Refai Nov 10 '17 at 5:55
  • 1
    The Terms property only contains child terms directly under the main term. I have a tree structure of child terms and need to get them all recursively – Rustam Nov 11 '17 at 17:40

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.