src/Solutions/Customization/AppModule/Set-XrmSiteMap.ps1
|
<# .SYNOPSIS Update a sitemap in Microsoft Dataverse. .DESCRIPTION Update the SiteMapXml attribute of an existing sitemap record. The sitemap defines the navigation structure of a model-driven app. .PARAMETER XrmClient Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient) .PARAMETER SiteMapReference EntityReference of the sitemap record to update. .PARAMETER SiteMapXml The sitemap XML content defining Areas, Groups, and SubAreas. .PARAMETER SolutionUniqueName Unmanaged solution unique name. When provided, the updated sitemap is automatically added to this solution. .OUTPUTS System.Void. .EXAMPLE $sitemaps = Get-XrmSiteMaps -Name "My SiteMap"; $sitemapRef = $sitemaps[0].Reference; Set-XrmSiteMap -SiteMapReference $sitemapRef -SiteMapXml $newXml; Set-XrmSiteMap -SiteMapReference $sitemapRef -SiteMapXml $newXml -SolutionUniqueName "MySolution"; .LINK https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/create-manage-model-driven-apps-using-code #> function Set-XrmSiteMap { [CmdletBinding()] [OutputType([System.Void])] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [Microsoft.Xrm.Sdk.EntityReference] $SiteMapReference, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $SiteMapXml, [Parameter(Mandatory = $false)] [string] $SolutionUniqueName ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $record = New-XrmEntity -LogicalName "sitemap"; $record.Id = $SiteMapReference.Id; $record["sitemapxml"] = $SiteMapXml; $XrmClient | Update-XrmRecord -Record $record; if ($PSBoundParameters.ContainsKey('SolutionUniqueName')) { Add-XrmSolutionComponent -XrmClient $XrmClient -SolutionUniqueName $SolutionUniqueName -ComponentId $SiteMapReference.Id -ComponentType 62 | Out-Null; } } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Set-XrmSiteMap -Alias *; |