Last active
June 27, 2020 13:27
-
-
Save michaellwest/3894cc032b33f0330c0a56b6a1bdf511 to your computer and use it in GitHub Desktop.
Generate a report of forms data 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
$selectedForm = Get-Item -Path "master:" -ID ([Sitecore.ExperienceForms.Client.Constants.GeneralConstants]::FormsFolderId) | |
$props = @{ | |
Parameters = @( | |
@{Name="selectedForm"; Value=$null; Title="Choose a form to filter out the results"; Tooltip=""; Editor="treelist"; Source="DataSource=$($selectedForm.ItemPath)&DatabaseName=master&IncludeTemplatesForDisplay=Folder,Form&IncludeTemplatesForSelection=Form"; }, | |
@{ Name = "startDate"; Value=[System.DateTime]::Now.AddDays(-30); Title="Start Date"; Tooltip="Earliest submitted entries to return"; Editor="date"; Columns=6; }, | |
@{ Name = "endDate"; Value=[System.DateTime]::Now; Title="End Date"; Tooltip="Latest submitted entries to return"; Editor="date"; Columns=6; } | |
) | |
Title = "Forms Report" | |
Icon = "OfficeWhite/32x32/clipboard_checks.png" | |
Description = "View a report of form submissions." | |
ShowHints = $true | |
} | |
$result = Read-Variable @props | |
if($result -eq "cancel"){ | |
exit | |
} | |
$formId = $selectedForm.ID.ToString() | |
$serviceType = [Sitecore.ExperienceForms.Data.IExportDataProvider] | |
$service = [Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider.GetService($serviceType) -as $serviceType | |
$exportedData = $service.Export($formId, $startDate.ToUniversalTime(), $endDate.ToUniversalTime()) | |
$reportData = ConvertFrom-Csv -InputObject $exportedData.Content -Delimiter ';' | |
if($reportData.Count -eq 0) { | |
Show-Alert "There are no items matching the specified criteria." | |
} else { | |
$props = @{ | |
Title = "Forms Report" | |
InfoTitle = "Forms Report" | |
InfoDescription = "Form data submitted between $($startDate) and $($endDate)." | |
} | |
$reportData | Show-ListView @props | |
} | |
Close-Window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment