Powershell script to read the field value single-line text form element in Sitecore Forms
write-host 'Running script...'
$Results = @();
#Get Form node
$FormNode = Get-Item -Path /sitecore/Forms
#Get all the sitecore form node's descendants
$descendants = Get-ChildItem -Path $FormNode.ID -Recurse
#Get single-line text fields from the forms
$singleLineFieldItems = $descendants | Where-Object { $_.TemplateName -eq "Input" }
#Loop through all the single line text field item and get the string value available in the "Binding Token" field
foreach ($singleLineFieldItem in $singleLineFieldItems) {
$selectedValueProvider = $singleLineFieldItem.Fields["Binding Token"].Value
write-host $singleLineFieldItem.Paths.Path
if ($selectedValueProvider -ne "") {
#Prepare columns with data to be appended in the csv or excel.
$Properties = @{
SelectedValueProvider = $selectedValueProvider
SingleLineFieldPath = $singleLineFieldItem.Paths.Path
}
#Add on the data in the $Results variable to provide it as a source of all the accumulated for excel or csv
$Results += New-Object psobject -Property $Properties
}
}
#Show all the data in tabular format so that it can be downloaded
$Results | Show-ListView -Property SelectedValueProvider, SingleLineFieldPath
write-host 'Script ended'
https://sitecorepeanuts.blogspot.com/2024/03/script-to-read-field-value-single-line.html
ReplyDelete