SitecorePowerShell/Console

$SitecoreContextItem variable lacks ItemPath property

lundebro opened this issue · 2 comments

Hi,
We're in the process of cleaning up some old scripts and based on the discussion in #1231 (comment) 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
  • Tested issue with clean install of Sitecore and the latest available version of SPE.

  • Asked questions on the Sitecore Slack Chat channel.

  • 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:

SetVariable("SitecoreContextItem", item);

Closing as it's implemented.