Created
February 13, 2019 21:34
-
-
Save michaellwest/1f032892fb6c31864d43016c0b65c7a8 to your computer and use it in GitHub Desktop.
Generate an item url given an item and the sitecontext using Sitecore PowerShell Extensions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ItemUrl { | |
param( | |
[item]$Item, | |
[Sitecore.Sites.SiteContext]$SiteContext | |
) | |
$result = New-UsingBlock(New-Object Sitecore.Sites.SiteContextSwitcher $siteContext) { | |
New-UsingBlock(New-Object Sitecore.Data.DatabaseSwitcher $item.Database) { | |
[Sitecore.Links.LinkManager]::GetItemUrl($item) | |
} | |
} | |
$result[0][0] | |
} | |
$siteContext = [Sitecore.Sites.SiteContext]::GetSite("website") | |
$item = Get-Item -Path "master:/content/home" | |
Get-ItemUrl -SiteContext $siteContext -Item $item |
We just want to break to Read :
ChallengeResponseUrl = $item.Fields["ChallengeResponseUrl"];
This shoud Rerturn : "/MC/Home/ChallengeErrorPage"
ChallengeResponseUrl Data Type is General Link Type
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many Thanks for Reply : :Asks is to Read Filed of type : Get Link type.
we have set value : /MC/Home/ChallengeErrorPage while authoring.
But when we are trying to Export Data it is returning value which is same as Raw Value. But we need : /MC/Home/ChallengeErrorPage while authoring.
We Required the solution using : Powershell Script.
ChallengeResponseUrl = $item.Fields["ChallengeResponseUrl"]; (How to Read General Link Fields and get User Friendly URL)
We want to return User-friendly URL (Using Powershell script) for item created using data type : General Link
Return Output :
"Item ID": "{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}",
"Item Name": "UpdateCard WorldPay 3DS Settings",
"challengeresponseurl": "\u003clink text="challengeresponse" anchor="" linktype="internal" class="" title="" querystring="" id="{A35EB771-4C8C-4DF4-9DD8-D751D01AA534}" /\u003e"
Expected Result :
"Item ID": "{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}",
"Item Name": "UpdateCard WorldPay 3DS Settings",
"challengeresponseurl": "/MC/Home/ChallengeErrorPage"
/* Code Start */
$itemList = Get-Item -Path "master:" -ID "
{FEDE8F7F-97C9-4C47-AE3D-D35E72BD1722} |
{2FA67EE6-E704-449E-8306-9583C4BA7AC3} |
{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}
" -Language en
$customList = New-Object System.Collections.Generic.List[pscustomobject]
ForEach ($item in $itemList) {
$newObject = New-Object PSObject @{
ChallengeResponseUrl = $item.Fields["ChallengeResponseUrl"];
}
$reportProps = @{
Title = “Report Title”
InfoTitle = “This is a heading of the report.”
InfoDescription = “Total entries found: $($itemList.length)”
PageSize = 10
}
$customList | Show-ListView @reportProps -Property `
@{ Name = “ChallengeResponseUrl”; Expression = { $.ChallengeResponseUrl}},
@{ Name = “ChallengeResponseUrlx”; Expression = { $.ChallengeResponseUrlx}}
/* Code End */
Out put :
Return Output :
"Item ID": "{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}",
"Item Name": "UpdateCard WorldPay 3DS Settings",
"challengeresponseurl": "\u003clink text="challengeresponse" anchor="" linktype="internal" class="" title="" querystring="" id="{A35EB771-4C8C-4DF4-9DD8-D751D01AA534}" /\u003e"
Expected Out Put :
"Item ID": "{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}",
"Item Name": "UpdateCard WorldPay 3DS Settings",
"challengeresponseurl": "/MC/Home/ChallengeErrorPage"