3

I am trying to get the raw values of fields of multiple items and display the result using Show-ListView. However, the result is not showing the values when it is enclosed in < > which can be found in cases such as the raw values of media fields and link fields. I believed it is treating them as HTML tags.

enter image description here

But when I download the result as CSV, the result is there. Now if I update the value to make < and > as &lt; and &gt; respectively, upon passing it to the listview object, I can make it display like what I want. But when downloaded as CSV, the values will show as &lt; and &gt; as well.

enter image description here

Is it possible to handle both? The goal is to show in listview the literal values of fields AND download it in CSV as it is.

2
  • can you share any code of what you have done so far Commented Jul 23 at 8:43
  • What version of SPE are you using? Commented Jul 23 at 16:36

1 Answer 1

2

You can use below snippet to display the image and link field raw values on the List View Panel, by using HtmlEncode function.

$item = Get-Item -Path "master:" -ID "{{ItemID}}"
$imageData = [System.Web.HttpUtility]::HtmlEncode($item.Fields["Image"].Value)

$customItem = [pscustomobject]@{
    "ID"= $item.ID
    "Icon"= $item.__Icon
    "Image"= $imageData
}

$customItem | Show-ListView

Thereafter when you download the CSV, it triggers the script located at following path:

/sitecore/system/Modules/PowerShell/Script Library/SPE/Core/Platform/Internal/List View/Export/CSV

You can modify this script as below to decode the Html values from the List View, with the help of HtmlDecode function.

$datetime = Get-Date -format "yyyy-MM-d_hhmmss"
$format = & ([scriptblock]::Create($exportProperty))

# Code to decode Html Values
foreach($exportRow in $exportData){
  $exportRow.PSObject.Properties | ForEach-Object {
    $_.Value = [System.Web.HttpUtility]::HtmlDecode($_.Value)
  }
}

[psCustomObject]$exportData | 
    Select-Object -Property $format | 
    ConvertTo-Csv -NoTypeInformation | 
    Out-String | 
    Out-Download -Name "report-$datetime.csv"

Using above way will help you to show the raw values for media and internal link fields, correctly on List view as well as CSV.

Hope this helps!!!

2
  • 1
    This is exactly what I needed. Thank you so much!
    – jeen15
    Commented Jul 24 at 4:38
  • @jeen15 Glad to hear that..Thank you!!!
    – ckhanna
    Commented Jul 24 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.