Skip to content
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

Set-ItemTemplate errors when the template is missing #1138

Closed
michaellwest opened this issue Sep 14, 2019 · 2 comments
Closed

Set-ItemTemplate errors when the template is missing #1138

michaellwest opened this issue Sep 14, 2019 · 2 comments
Assignees
Labels
area-commands Involves functions and cmdlets. improvement Extra sugar and spice.
Milestone

Comments

@michaellwest
Copy link
Member

Expected Behavior

Running the following command should work without error.

$item = Get-Item -Path "master:" -ID "{5C761140-7076-4F82-A2D9-473FDC5635C8}"
$newTemplate = Get-Item -Path "master:" -ID "{B0B6FB08-6BBE-43F2-8E36-FCE228325B63}"

Set-ItemTemplate -ID $item.ID -TemplateItem $newTemplate

Actual Behavior

An error is returned stating that the object is null.

@michaellwest michaellwest self-assigned this Sep 14, 2019
@michaellwest michaellwest added this to the 6.0 milestone Sep 14, 2019
@michaellwest michaellwest added area-commands Involves functions and cmdlets. improvement Extra sugar and spice. labels Sep 14, 2019
@michaellwest
Copy link
Member Author

An edge case was revealed in this Sitecore Stack Exchange question.

Turns out that the issue happens when calling item.ChangeTemplate() but can be fixed when calling TemplateManager.ChangeTemplate().

michaellwest added a commit that referenced this issue Sep 14, 2019
The developer may already know that the template is missing.
@michaellwest
Copy link
Member Author

@dresser hopefully this simplifies your script in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commands Involves functions and cmdlets. improvement Extra sugar and spice.
Projects
No open projects
Development

No branches or pull requests

1 participant