src/Solutions/Customization/Forms/Get-XrmForms.ps1
|
<# .SYNOPSIS Retrieve form records from Microsoft Dataverse. .DESCRIPTION Get systemform records (forms) filtered by entity logical name and optionally by form type. Use -Unpublished to also retrieve forms that are in draft state. .PARAMETER XrmClient Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient) .PARAMETER EntityLogicalName Table / Entity logical name to filter forms. Optional. .PARAMETER FormType Form type filter (0=Dashboard, 2=Main, 5=Mobile, 6=QuickCreate, 7=QuickView). Optional. .PARAMETER Columns Specify expected columns to retrieve. (Default : all columns) .PARAMETER Unpublished When specified, uses RetrieveUnpublishedMultiple to include forms in draft (unpublished) state. Without this switch only published forms are returned. .OUTPUTS PSCustomObject[]. Array of systemform records (XrmObject). .EXAMPLE $forms = Get-XrmForms -EntityLogicalName "account"; $mainForms = Get-XrmForms -EntityLogicalName "account" -FormType 2; $dashboards = Get-XrmForms -FormType 0; .EXAMPLE # Include unpublished drafts $allForms = Get-XrmForms -EntityLogicalName "account" -Unpublished; #> function Get-XrmForms { [CmdletBinding()] [OutputType([PSCustomObject[]])] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [string] $EntityLogicalName, [Parameter(Mandatory = $false)] [int] $FormType, [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [string[]] $Columns = @("*"), [Parameter(Mandatory = $false)] [switch] $Unpublished ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $query = New-XrmQueryExpression -LogicalName "systemform" -Columns $Columns; if ($PSBoundParameters.ContainsKey('EntityLogicalName')) { $query = $query | Add-XrmQueryCondition -Field "objecttypecode" -Condition Equal -Values $EntityLogicalName; } if ($PSBoundParameters.ContainsKey('FormType')) { $query = $query | Add-XrmQueryCondition -Field "type" -Condition Equal -Values $FormType; } $XrmClient | Get-XrmMultipleComponents -Query $query -Unpublished:$Unpublished; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-XrmForms -Alias *; |