gpt4 book ai didi

powershell - Sitecore Powershell 报告/ListView : retrieving items from ID returned by the query

转载 作者:行者123 更新时间:2023-12-01 00:58:47 24 4
gpt4 key购买 nike

名为“User”的模板有一个名为“Location”的字段,它是另一个项目的 ID;在 Powershell 中,我使用 Show-ListView 返回字段列表,但 Location 显示原始 ID,而我更愿意显示所涉及位置的名称。

我试图检索此信息,但不确定 Powershell 查询中可用的语法。我的尝试如下:

Get-Item master: -Query "/sitecore/content/sites/data/people//*[@@templatename='Person']" |
Show-ListView -property "First Name",
@{Label="Surname"; Expression={$_."Surname"}},
@{Label="Location"; Expression={[Sitecore.Context.Database.GetItem]::FromId($_."Location").Title}}

...什么也没有产生。

$_."Location"

是元素的ID;有没有办法检索它的字段?

最佳答案

secret 在于默认情况下 Sitecore 没有从字段转换的方便属性。在本例中,我们讨论的是位置项上的 Title 属性。你可以做的是:

1) 像这样通过提供者获取位置项目:

Get-Item master: -Query "/sitecore/content/sites/data/people//*[@@templatename='Person']" |
Show-ListView -property "First Name",
@{Label="Surname"; Expression={$_."Surname"}},
@{Label="Location"; Expression={(Get-Item master:\ -ID $_."Location").Title}}

注意最后一行对 Get-Item 的调用。

2) 如果您出于某种原因需要通过 Sitecore API 获取它,您可以将它通过管道传递给 Initialize-Item,我们会像这样将这些属性包装在 Item 对象周围:

Get-Item master: -Query "/sitecore/content/sites/data/people//*[@@templatename='Person']" |
Show-ListView -property "First Name",
@{Label="Surname"; Expression={$_."Surname"}},
@{Label="Location"; Expression={([Sitecore.Configuration.Factory]::GetDatabase("master").GetItem($_."Location") | Initialize-Item).Title}}

关于powershell - Sitecore Powershell 报告/ListView : retrieving items from ID returned by the query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37943690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com