Console
Console copied to clipboard
$SitecoreContextItem variable lacks ItemPath property
Hi,
We're in the process of cleaning up some old scripts and based on the discussion in https://github.com/SitecorePowerShell/Console/issues/1231#issuecomment-799529532 we're replacing every usage of Get-Item . with $SitecoreContextItem. Upon doing so we discovered that the ItemPath property doesn't exist.
It can be remedied by replacing every usage of ItemPath with Paths.Path but it's a bit confusing why this behavior occurs. ItemPath is also mentioned in the docs, for instance on https://doc.sitecorepowershell.com/training so it makes sense that you would try to use it.
Looking at the code here on Github it looks like ItemPath is a custom property defined in https://github.com/SitecorePowerShell/Console/blob/master/src/Spe/Core/Extensions/ItemShellExtensions.cs so maybe this is by design, and if so you may of course close this issue. But I still think it's confusing to the user that items fetched by Get-Item . and $SitecoreContextItem don't contain the same properties, even though they look to be of the same type.
Expected Behavior
$SitecoreContextItem.ItemPath should return the path to the context item, the same way (Get-Item .).ItemPath does.
Actual Behavior
$SitecoreContextItem.ItemPath returns null
Steps to Reproduce the Problem
Just run the commands above, or compare the output between the two commands below:
(Get-Item .) | Format-List
$SitecoreContextItem | Format-List
-
[x] Tested issue with clean install of Sitecore and the latest available version of SPE.
-
[ ] Asked questions on the Sitecore Slack Chat channel.
-
[x] Reviewed questions and answers on the Sitecore Stack Exchange.
Seems reasonable that it should have that.
Here's an example of where it's missing:
https://github.com/SitecorePowerShell/Console/blob/a13af4e24f0de98efbce3931be20540a603855c6/src/Spe/Core/Host/ScriptSession.cs#L835
Closing as it's implemented.