Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active June 27, 2020 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/3894cc032b33f0330c0a56b6a1bdf511 to your computer and use it in GitHub Desktop.
Save michaellwest/3894cc032b33f0330c0a56b6a1bdf511 to your computer and use it in GitHub Desktop.
Generate a report of forms data using Sitecore PowerShell Extensions.
$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