Skip to content

Fix #2152 - issue with Add-PnPTaxonomyField #2351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed `Copy-PnPList` cmdlet to be able to copy the list structure to the destination web. [#2313](https://github.com/pnp/powershell/pull/2313)
- Fixed `Add-PnPField` cmdlet , it was throwing null reference error when `-Type` was not specified and after the prompt you entered the correct type. [#2338](https://github.com/pnp/powershell/pull/2338)
- Fixed regression issue with `New-Microsoft365Group` cmdlet. [#2349](https://github.com/pnp/powershell/pull/2349)
- Fixed issue with `Add-PnPTaxonomyField`, it was throwing error when using `-TaxonomyItemId` parameter.

### Contributors

- Marc Studer [Studermarc]
Expand Down
9 changes: 5 additions & 4 deletions src/Commands/Fields/AddTaxonomyField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override void ExecuteCmdlet()
{
TaxonomyItem taxItem;
Field field;

if (ParameterSetName == "Path")
{
taxItem = ClientContext.Site.GetTaxonomyItemByPath(TermSetPath, TermPathDelimiter);
Expand All @@ -65,19 +65,20 @@ protected override void ExecuteCmdlet()
try
{
taxItem = termStore.GetTermSet(TaxonomyItemId);
taxItem.EnsureProperty(t => t.Id);
}
catch
{
try
{
taxItem = termStore.GetTerm(TaxonomyItemId);
taxItem.EnsureProperty(t => t.Id);
}
catch
{
throw new Exception($"Taxonomy Item with Id {TaxonomyItemId} not found");
}
}
taxItem.EnsureProperty(t => t.Id);
}

if (Id == Guid.Empty)
Expand All @@ -99,8 +100,8 @@ protected override void ExecuteCmdlet()

if (ParameterSpecified(nameof(FieldOptions)))
{
fieldCI.FieldOptions = FieldOptions;
}
fieldCI.FieldOptions = FieldOptions;
}

if (List != null)
{
Expand Down