Skip to content

Commit

Permalink
Fix #468: Refactor GetTerm method to properly load child terms and re…
Browse files Browse the repository at this point in the history
…trieve a specific term by ID or name (#4454)

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored Oct 19, 2024
1 parent 188cca0 commit f1b45d6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Commands/Taxonomy/GetTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GetTerm : PnPRetrievalsCmdlet<Term>

[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public SwitchParameter IncludeChildTerms;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_TERMNAME)]
public TaxonomyTermPipeBind ParentTerm;

Expand Down Expand Up @@ -67,7 +67,7 @@ protected override void ExecuteCmdlet()
LoadChildTerms(term);
}
WriteObject(term);
}
}
else
{
throw new PSArgumentException("Insufficient Parameters specified to determine the term to retrieve");
Expand All @@ -90,7 +90,21 @@ protected override void ExecuteCmdlet()
}
else if (Identity != null && ParentTerm != null)
{
var term = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated);
var parentTerm = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated);
LoadChildTerms(parentTerm);

Term term = null;
if (Identity.Id != Guid.Empty)
{
term = parentTerm.Terms.GetById(Identity.Id);
}
else
{
term = parentTerm.Terms.GetByName(Identity.Title);
}

ClientContext.Load(term, RetrievalExpressions);
ClientContext.ExecuteQueryRetry();

if (IncludeChildTerms.IsPresent && term.TermsCount > 0)
{
Expand Down

0 comments on commit f1b45d6

Please sign in to comment.