From c450a5ed61d31b9a3a117a47e85fbd1da7aae223 Mon Sep 17 00:00:00 2001 From: Torsten Brendgen Date: Thu, 16 Jul 2026 23:37:23 +0200 Subject: [PATCH] =?UTF-8?q?Aktualisiere=20die=20README.md=20mit=20Anweisun?= =?UTF-8?q?gen=20zur=20Registrierung=20des=20Field=20Customizers=20und=20C?= =?UTF-8?q?ommand=20Sets;=20f=C3=BCge=20neue=20Parameter=20f=C3=BCr=20Comm?= =?UTF-8?q?and=20Set=20IDs=20in=20Enable-=20und=20Disable-ExpiryIndicator.?= =?UTF-8?q?ps1=20hinzu;=20erstelle=20Test-ExpiryIndicatorRegistration.ps1?= =?UTF-8?q?=20zur=20=C3=9Cberpr=C3=BCfung=20der=20Registrierung.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +-- scripts/Disable-ExpiryIndicator.ps1 | 29 ++++++++---- scripts/Enable-ExpiryIndicator.ps1 | 30 ++++++++++-- scripts/Test-ExpiryIndicatorRegistration.ps1 | 50 ++++++++++++++++++++ 4 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 scripts/Test-ExpiryIndicatorRegistration.ps1 diff --git a/README.md b/README.md index 446e4d2..02cc57f 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,8 @@ Nach **Speichern** wird die Konfiguration pro Liste beziehungsweise Bibliothek i ### Anzeige aktivieren -Die Einstellungen registrieren noch nicht den Field Customizer an der kundenspezifischen Ablaufdatumsspalte. -Diese Zuordnung erfolgt einmal pro Feld mit dem mitgelieferten Skript: +Der Field Customizer und das Command Set werden einmal pro Liste beziehungsweise Bibliothek mit dem +mitgelieferten Skript registriert: ```powershell .\scripts\Enable-ExpiryIndicator.ps1 ` @@ -220,7 +220,8 @@ Diese Zuordnung erfolgt einmal pro Feld mit dem mitgelieferten Skript: ``` Der Wert von `ExpiryFieldInternalName` muss mit **Internes Ablaufdatumsfeld** in den Einstellungen -übereinstimmen. Danach die Listenansicht neu laden. +übereinstimmen. Das Skript registriert zugleich die Befehle **Expiry-Einstellungen** und +**Ablaufdatum +1 Jahr**. Danach die Listenansicht neu laden. ### Ablaufdatum um ein Jahr verlängern diff --git a/scripts/Disable-ExpiryIndicator.ps1 b/scripts/Disable-ExpiryIndicator.ps1 index 0b9bdda..fa6ba0f 100644 --- a/scripts/Disable-ExpiryIndicator.ps1 +++ b/scripts/Disable-ExpiryIndicator.ps1 @@ -9,7 +9,9 @@ param( [Parameter(Mandatory = $true)] [string]$ExpiryFieldInternalName, - [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde' + [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde', + + [Guid]$CommandSetComponentId = 'cd58f5d9-ffc8-4df7-a910-3054842d7abf' ) $isapiPath = Join-Path ([Environment]::GetFolderPath('CommonProgramFiles')) 'microsoft shared\Web Server Extensions\16\ISAPI' @@ -22,23 +24,30 @@ $context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials try { $list = $context.Web.Lists.GetByTitle($ListTitle) $field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName) + $customActions = $list.UserCustomActions $context.Load($list) $context.Load($field) + $context.Load($customActions) $context.ExecuteQuery() - if ($field.ClientSideComponentId -ne $FieldCustomizerComponentId) { - throw "Das Feld '$($field.InternalName)' ist nicht mit dem erwarteten ExpiryIndicator-Field-Customizer verbunden." - } + if ($PSCmdlet.ShouldProcess("$($list.Title)/$($field.InternalName)", 'ExpiryIndicator-Registrierungen entfernen')) { + if ($field.ClientSideComponentId -eq $FieldCustomizerComponentId) { + $field.ClientSideComponentId = [Guid]::Empty + $field.ClientSideComponentProperties = '' + $field.Update() + } + + $customActions | Where-Object { + $_.Name -eq 'ExpiryIndicator.CommandSet' -or + $_.ClientSideComponentId -eq $CommandSetComponentId + } | ForEach-Object { + $_.DeleteObject() + } - if ($PSCmdlet.ShouldProcess("$($list.Title)/$($field.InternalName)", 'Field-Customizer-Verknüpfung entfernen')) { - $field.ClientSideComponentId = [Guid]::Empty - $field.ClientSideComponentProperties = '' - $field.Update() $context.ExecuteQuery() - Write-Host "ExpiryIndicator-Verknüpfung wurde entfernt. Feld und Daten bleiben unverändert." + Write-Host 'ExpiryIndicator-Registrierungen wurden entfernt. Feld und Daten bleiben unverändert.' } } finally { $context.Dispose() } - diff --git a/scripts/Enable-ExpiryIndicator.ps1 b/scripts/Enable-ExpiryIndicator.ps1 index 87fae5b..59f66b1 100644 --- a/scripts/Enable-ExpiryIndicator.ps1 +++ b/scripts/Enable-ExpiryIndicator.ps1 @@ -9,7 +9,9 @@ param( [Parameter(Mandatory = $true)] [string]$ExpiryFieldInternalName, - [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde' + [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde', + + [Guid]$CommandSetComponentId = 'cd58f5d9-ffc8-4df7-a910-3054842d7abf' ) $isapiPath = Join-Path ([Environment]::GetFolderPath('CommonProgramFiles')) 'microsoft shared\Web Server Extensions\16\ISAPI' @@ -22,22 +24,42 @@ $context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials try { $list = $context.Web.Lists.GetByTitle($ListTitle) $field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName) + $customActions = $list.UserCustomActions $context.Load($list) $context.Load($field) + $context.Load($customActions) $context.ExecuteQuery() if ($field.InternalName -ne $ExpiryFieldInternalName) { - Write-Warning "Das Feld wurde über seinen Anzeigenamen gefunden. Für eine stabile Konfiguration sollte der interne Name '$($field.InternalName)' verwendet werden." + Write-Warning "Das Feld wurde über seinen Anzeigenamen gefunden. Verwende künftig den internen Namen '$($field.InternalName)'." } $field.ClientSideComponentId = $FieldCustomizerComponentId $field.ClientSideComponentProperties = '{}' $field.Update() + + $commandAction = $customActions | Where-Object { + $_.Name -eq 'ExpiryIndicator.CommandSet' -or + $_.ClientSideComponentId -eq $CommandSetComponentId + } | Select-Object -First 1 + + if ($null -eq $commandAction) { + $commandAction = $customActions.Add() + } + + $commandAction.Name = 'ExpiryIndicator.CommandSet' + $commandAction.Title = 'ExpiryIndicator commands' + $commandAction.Location = 'ClientSideExtension.ListViewCommandSet.CommandBar' + $commandAction.ClientSideComponentId = $CommandSetComponentId + $commandAction.ClientSideComponentProperties = '{}' + $commandAction.Update() + $context.ExecuteQuery() - Write-Host "ExpiryIndicator wurde für '$($list.Title)' an '$($field.InternalName)' gebunden." + Write-Host "Field Customizer wurde an '$($field.InternalName)' gebunden." + Write-Host "Command Set wurde an '$($list.Title)' registriert." + Write-Host 'Bitte die moderne Listenansicht mit Strg+F5 neu laden.' } finally { $context.Dispose() } - diff --git a/scripts/Test-ExpiryIndicatorRegistration.ps1 b/scripts/Test-ExpiryIndicatorRegistration.ps1 new file mode 100644 index 0000000..66c5028 --- /dev/null +++ b/scripts/Test-ExpiryIndicatorRegistration.ps1 @@ -0,0 +1,50 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $true)] + [string]$SiteUrl, + + [Parameter(Mandatory = $true)] + [string]$ListTitle, + + [Parameter(Mandatory = $true)] + [string]$ExpiryFieldInternalName +) + +$isapiPath = Join-Path ([Environment]::GetFolderPath('CommonProgramFiles')) 'microsoft shared\Web Server Extensions\16\ISAPI' +Add-Type -Path (Join-Path $isapiPath 'Microsoft.SharePoint.Client.Runtime.dll') +Add-Type -Path (Join-Path $isapiPath 'Microsoft.SharePoint.Client.dll') + +$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) +$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials + +try { + $list = $context.Web.Lists.GetByTitle($ListTitle) + $field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName) + $customActions = $list.UserCustomActions + $context.Load($list) + $context.Load($field) + $context.Load($customActions) + $context.ExecuteQuery() + + Write-Host "Liste: $($list.Title)" + Write-Host "Feld: $($field.InternalName)" + Write-Host "Field Customizer: $($field.ClientSideComponentId)" + Write-Host '' + Write-Host 'List User Custom Actions:' + + $actions = @($customActions | Where-Object { + $_.Location -like 'ClientSideExtension.ListViewCommandSet*' -or + $_.Name -like 'ExpiryIndicator*' + }) + + if ($actions.Count -eq 0) { + Write-Warning 'Kein ExpiryIndicator Command Set an der Liste registriert.' + } + else { + $actions | Select-Object Name, Title, Location, ClientSideComponentId, ClientSideComponentProperties | + Format-List + } +} +finally { + $context.Dispose() +}