chore: update version to 2.0.1 and enhance Classic functionality with dynamic field discovery

This commit is contained in:
Torsten Brendgen
2026-07-18 20:02:49 +02:00
parent 0d6768e24c
commit 0d6da3451d
11 changed files with 71 additions and 20 deletions

View File

@@ -9,7 +9,9 @@ param(
[Parameter(Mandatory = $true)]
[string]$ExpiryFieldInternalName,
[Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde'
[Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde',
[switch]$RemoveClassicWebScriptLink
)
$isapiPath = Join-Path ([Environment]::GetFolderPath('CommonProgramFiles')) 'microsoft shared\Web Server Extensions\16\ISAPI'
@@ -23,9 +25,11 @@ try {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName)
$customActions = $list.UserCustomActions
$webCustomActions = $context.Web.UserCustomActions
$context.Load($list)
$context.Load($field)
$context.Load($customActions)
$context.Load($webCustomActions)
$context.ExecuteQuery()
if ($field.ClientSideComponentId -ne $FieldCustomizerComponentId) {
@@ -44,8 +48,19 @@ try {
$_.DeleteObject()
}
if ($RemoveClassicWebScriptLink) {
$webCustomActions | Where-Object {
$_.Name -eq 'ExpiryIndicator.Classic.ScriptLink'
} | ForEach-Object {
$_.DeleteObject()
}
}
$context.ExecuteQuery()
Write-Host 'ExpiryIndicator-Verknüpfung und Classic-Registrierungen wurden entfernt. Feld und Daten bleiben unverändert.'
Write-Host 'ExpiryIndicator-Verknüpfung und listenspezifische Classic-Registrierungen wurden entfernt. Feld und Daten bleiben unverändert.'
if (-not $RemoveClassicWebScriptLink) {
Write-Host 'Der gemeinsam verwendete Classic-Web-ScriptLink bleibt bestehen. Verwende -RemoveClassicWebScriptLink, wenn keine weitere Liste ihn benötigt.'
}
}
}
finally {

View File

@@ -27,9 +27,11 @@ try {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName)
$customActions = $list.UserCustomActions
$webCustomActions = $context.Web.UserCustomActions
$context.Load($list)
$context.Load($field)
$context.Load($customActions)
$context.Load($webCustomActions)
$context.ExecuteQuery()
if ($field.InternalName -ne $ExpiryFieldInternalName) {
@@ -55,15 +57,25 @@ try {
$_.DeleteObject()
}
if (-not $SkipClassic) {
$webCustomActions | Where-Object {
$_.Name -eq 'ExpiryIndicator.Classic.ScriptLink'
} | ForEach-Object {
$_.DeleteObject()
}
}
$context.ExecuteQuery()
if (-not $SkipClassic) {
$scriptAction = $list.UserCustomActions.Add()
# SharePoint permits Location=ScriptLink only on Web/Site custom
# actions, not on List.UserCustomActions. The runtime detects the
# current list and its bound expiry field by itself.
$scriptAction = $context.Web.UserCustomActions.Add()
$scriptAction.Name = 'ExpiryIndicator.Classic.ScriptLink'
$scriptAction.Title = 'ExpiryIndicator Classic runtime'
$scriptAction.Location = 'ScriptLink'
$separator = if ($ClassicScriptUrl.Contains('?')) { '&' } else { '?' }
$scriptAction.ScriptSrc = $ClassicScriptUrl + $separator + 'expiryField=' + [Uri]::EscapeDataString($field.InternalName)
$scriptAction.ScriptSrc = $ClassicScriptUrl
$scriptAction.Sequence = 650
$scriptAction.Update()
@@ -103,7 +115,7 @@ try {
$ribbonAction.Update()
$context.ExecuteQuery()
Write-Host 'Classic-Ansicht: CSR/JSLink und Ribbon-Befehl wurden registriert.'
Write-Host 'Classic-Ansicht: Web-ScriptLink und listenspezifischer Ribbon-Befehl wurden registriert.'
}
Write-Host "ExpiryIndicator wurde für '$($list.Title)' an '$($field.InternalName)' gebunden."