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

Ancestor queries not working with Get-Item #1069

Closed
michaellwest opened this Issue Nov 1, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@michaellwest
Member

michaellwest commented Nov 1, 2018

Expected Behavior

The queries return items like that seen in the XPathBuilder.

https://spe.dev.local/sitecore/shell/default.aspx?xmlcontrol=IDE.XPath.Builder

image

Actual Behavior

No results returned.

Steps to Reproduce the Problem

Run the following commands:

Get-Item master: -Query "ancestor-or-self::*"
Get-Item master: -Query "./ancestor-or-self::*"
Get-Item master: -Query "ancestor-or-self::*[@@templatename='Sample Item']"
Get-Item master: -Query "./ancestor-or-self::*[@@templatename='Sample Item']"

Thanks for reporting @jammykam!

@michaellwest

This comment has been minimized.

Member

michaellwest commented Nov 2, 2018

Looks like this can be achieved @jammykam.

# Set the current location in ISE to master:\content\home\demo
$query = "ancestor-or-self::*[@@templatename='Sample Item']"
$SitecoreContextItem.Axes.SelectItems($query)
[Sitecore.Data.Query.Query]::SelectItems($query, $SitecoreContextItem)
Get-Item -Path "master:" -Query ("$($SitecoreContextItem.Paths.Path)/$query")

<#

Name                             Children Language Version Id                                     TemplateName
----                             -------- -------- ------- --                                     ------------
Demo                             False    en       1       {E3D16DC4-D258-4000-8D75-8187446C6D19} Sample Item
Demo                             False    en       1       {E3D16DC4-D258-4000-8D75-8187446C6D19} Sample Item
Demo                             False    en       1       {E3D16DC4-D258-4000-8D75-8187446C6D19} Sample Item
#>

@michaellwest michaellwest removed the bug label Nov 2, 2018

@michaellwest michaellwest added this to the User Support milestone Nov 2, 2018

@jammykam

This comment has been minimized.

jammykam commented Nov 2, 2018

Yes, it can be achieved using those methods, but it's a workaround to running an actual Xpath query when passing in a -Query parameter.

Take the following example, which also does not work:

cd "master:/content/Project/Home/Test1/Test2"
Get-Item master: -Query "../../../*"

As you say, we can workaround this limitation:

$SitecoreContextItem = Get-Item -Path "master:/content/Project/Home/Test1/Test2"
$SitecoreContextItem.Axes.SelectItems("../../../*")

Alternatively:

cd "master:/content/Project/Home/Test1/Test2"
$item = gi .
$item.Axes.SelectItems("../../../*")

These are probably infrequently used types of queries. Perhaps it will be sufficient to add these snippets in the book, so people are aware of the limitation.

@michaellwest

This comment has been minimized.

Member

michaellwest commented Nov 2, 2018

Good idea on adding to the docs. That's posted now.

@michaellwest michaellwest self-assigned this Nov 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment