-
-
Save michaellwest/1f032892fb6c31864d43016c0b65c7a8 to your computer and use it in GitHub Desktop.
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 |
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"];
[Sitecore.Data.Fields.LinkField]$linkField = $item.Fields["ChallengeResponseUrl"];
ChallengeResponseUrlx = $linkField.Paths.FullPath;
}
$customList.Add($newObject)
}
$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"
We just want to break to Read :
ChallengeResponseUrl = $item.Fields["ChallengeResponseUrl"];
This shoud Rerturn : "/MC/Home/ChallengeErrorPage"
ChallengeResponseUrl Data Type is General Link Type
General Link data type filed is Not returning User-friendly URL.
It is returning data :
"challengeresponseurl": "\u003clink text="challengeresponse" anchor="" linktype="internal" class="" title="" querystring="" id="{A35EB771-4C8C-4DF4-9DD8-D751D01AA534}" /\u003e"
$itemList = Get-Item -Path "master:" -ID "
{FEDE8F7F-97C9-4C47-AE3D-D35E72BD1722} |
{8B1230F4-F09D-4577-BD3D-1071BEECEAC4}
" -Language 'en'
$customList = New-Object System.Collections.Generic.List[pscustomobject]
ForEach ($item in $itemList) {
$newObject = New-Object PSObject @{
ItemId = $item.Id;
ItemName = $item.DisplayName;
challengeresponseurl = $item."challengeresponseurl";
}
$customList.Add($newObject)
}
$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 = “Item ID”; Expression = { $.ItemId}},
@{ Name = “Item Name”; Expression = { $.ItemName}},
@{ Name = “challengeresponseurl”; Expression = { $_.challengeresponseurl}}
Could you please suggest what wrong I am doing....