diff --git a/CHANGELOG.md b/CHANGELOG.md index a543f73..40a9eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [3.4.3] - 06-02-2026 + +List of changes: +- Removed `lookupErrorTopdesk` [#44](https://github.com/Tools4everBV/HelloID-Conn-Prov-Target-Topdesk/issues/44) +- `Confirm-Description` now shorten the `BriefDescription` and `requestShort` +- Added support to not update branch in update script (when not update is not selected on `branch.name`) +- Fixed [#37](https://github.com/Tools4everBV/HelloID-Conn-Prov-Target-Topdesk/issues/37) + ## [3.4.2] - 19-01-2026 Updated contract endpoint datetime conversion for better timezone support. diff --git a/configuration.json b/configuration.json index fe937bb..16541b2 100644 --- a/configuration.json +++ b/configuration.json @@ -79,24 +79,6 @@ "required": false } }, - { - "key": "lookupErrorTopdesk", - "type": "radio", - "defaultValue": "true", - "templateOptions": { - "label": "When an item can't be found in Topdesk", - "options": [ - { - "value": "true", - "label": "Stop processing and generate an error" - }, - { - "value": "false", - "label": "Keep the current value and continue" - } - ] - } - }, { "key": "lookupErrorHrDepartment", "type": "radio", diff --git a/create.ps1 b/create.ps1 index ade7ebc..8e8fa50 100644 --- a/create.ps1 +++ b/create.ps1 @@ -136,9 +136,6 @@ function Get-TopdeskDepartment { [ValidateNotNullOrEmpty()] $LookupErrorHrDepartment, - [ValidateNotNullOrEmpty()] - $LookupErrorTopdesk, - [ValidateNotNullOrEmpty()] [Object] [ref]$Account @@ -180,19 +177,10 @@ function Get-TopdeskDepartment { # When department is not found in Topdesk if ([string]::IsNullOrEmpty($department.id)) { - if ([System.Convert]::ToBoolean($LookupErrorTopdesk)) { - # True, no department found = throw error - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = "Department [$($Account.department.name)] not found in Topdesk and the connector is configured to stop when this happens." - IsError = $true - }) - } - else { - # False, no department found = remove department field (leave empty on creation or keep current value on update) - $Account.department.PSObject.Properties.Remove('name') - $Account.PSObject.Properties.Remove('department') - Write-Information "Not overwriting or setting department as it can't be found in Topdesk. (lookupErrorTopdesk = False)" - } + $outputContext.AuditLogs.Add([PSCustomObject]@{ + Message = "Department [$($Account.department.name)] not found in Topdesk and the connector is configured to stop when this happens." + IsError = $true + }) } else { # Department is found in Topdesk, set in Topdesk @@ -215,9 +203,6 @@ function Get-TopdeskBudgetHolder { [ValidateNotNullOrEmpty()] $LookupErrorHrBudgetHolder, - [ValidateNotNullOrEmpty()] - $LookupErrorTopdesk, - [ValidateNotNullOrEmpty()] [Object] [ref]$Account @@ -261,19 +246,10 @@ function Get-TopdeskBudgetHolder { # When budgetholder is not found in Topdesk if ([string]::IsNullOrEmpty($budgetHolder.id)) { - if ([System.Convert]::ToBoolean($lookupErrorTopdesk)) { - # True, no budgetholder found = throw error - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = "Budgetholder [$($Account.budgetHolder.name)] not found in Topdesk and the connector is configured to stop when this happens." - IsError = $true - }) - } - else { - # False, no budgetholder found = remove budgetholder field (leave empty on creation or keep current value on update) - $Account.budgetHolder.PSObject.Properties.Remove('name') - $Account.PSObject.Properties.Remove('budgetHolder') - Write-Information "Not overwriting or setting budgetholder as it can't be found in Topdesk. (lookupErrorTopdesk = False)" - } + $outputContext.AuditLogs.Add([PSCustomObject]@{ + Message = "Budgetholder [$($Account.budgetHolder.name)] not found in Topdesk and the connector is configured to stop when this happens." + IsError = $true + }) } else { # Budgetholder is found in Topdesk, set in Topdesk @@ -640,7 +616,6 @@ try { Headers = $authHeaders BaseUrl = $actionContext.Configuration.baseUrl LookupErrorHrDepartment = $actionContext.Configuration.lookupErrorHrDepartment - LookupErrorTopdesk = $actionContext.Configuration.lookupErrorTopdesk } Get-TopdeskDepartment @splatParamsDepartment } @@ -655,7 +630,6 @@ try { Headers = $authHeaders BaseUrl = $actionContext.Configuration.baseUrl lookupErrorHrBudgetHolder = $actionContext.Configuration.lookupErrorHrBudgetHolder - lookupErrorTopdesk = $actionContext.Configuration.lookupErrorTopdesk } Get-TopdeskBudgetholder @splatParamsBudgetHolder } diff --git a/permissions/change/grantPermission.ps1 b/permissions/change/grantPermission.ps1 index a14908c..99e2214 100644 --- a/permissions/change/grantPermission.ps1 +++ b/permissions/change/grantPermission.ps1 @@ -263,12 +263,12 @@ function Confirm-Description { $AllowedLength ) if ($Description.Length -gt $AllowedLength) { - $errorMessage = "Could not grant TOPdesk entitlement [$id]: The attribute [$AttributeName] exceeds the max amount of [$AllowedLength] characters. Please shorten the value for this attribute in the JSON file. Value: [$Description]" - - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = $errorMessage - IsError = $true - }) + Write-Information "Attribute [$AttributeName] exceeds [$AllowedLength] characters [$Description] and will be shortened." + $descriptionShortened = $Description.substring(0, [System.Math]::Min($AllowedLength, $Description.Length)) + return $descriptionShortened + } + else { + return $Description } } @@ -732,13 +732,12 @@ try { Description = $briefDescription AllowedLength = 80 AttributeName = 'BriefDescription' - id = $pref.id + id = $pRef.id } - Confirm-Description @splatParamsValidateBriefDescription - + # Add value to request object $requestObject += @{ - briefDescription = $briefDescription + briefDescription = Confirm-Description @splatParamsValidateBriefDescription } # Resolve variables in the request field diff --git a/permissions/change/revokePermission.ps1 b/permissions/change/revokePermission.ps1 index 9fa4f9c..3c1640c 100644 --- a/permissions/change/revokePermission.ps1 +++ b/permissions/change/revokePermission.ps1 @@ -263,12 +263,12 @@ function Confirm-Description { $AllowedLength ) if ($Description.Length -gt $AllowedLength) { - $errorMessage = "Could not revoke TOPdesk entitlement [$id]: The attribute [$AttributeName] exceeds the max amount of [$AllowedLength] characters. Please shorten the value for this attribute in the JSON file. Value: [$Description]" - - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = $errorMessage - IsError = $true - }) + Write-Information "Attribute [$AttributeName] exceeds [$AllowedLength] characters [$Description] and will be shortened." + $descriptionShortened = $Description.substring(0, [System.Math]::Min($AllowedLength, $Description.Length)) + return $descriptionShortened + } + else { + return $Description } } @@ -733,13 +733,12 @@ try { Description = $briefDescription AllowedLength = 80 AttributeName = 'BriefDescription' - id = $pref.id + id = $pRef.id } - Confirm-Description @splatParamsValidateBriefDescription - + # Add value to request object $requestObject += @{ - briefDescription = $briefDescription + briefDescription = Confirm-Description @splatParamsValidateBriefDescription } # Resolve variables in the request field diff --git a/permissions/incident/grantPermission.ps1 b/permissions/incident/grantPermission.ps1 index c762fb1..dea4a84 100644 --- a/permissions/incident/grantPermission.ps1 +++ b/permissions/incident/grantPermission.ps1 @@ -226,12 +226,12 @@ function Confirm-Description { $AllowedLength ) if ($Description.Length -gt $AllowedLength) { - $errorMessage = "Could not grant TOPdesk entitlement [$id]: The attribute [$AttributeName] exceeds the max amount of [$AllowedLength] characters. Please shorten the value for this attribute in the JSON file. Value: [$Description]" - - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = $errorMessage - IsError = $true - }) + Write-Information "Attribute [$AttributeName] exceeds [$AllowedLength] characters [$Description] and will be shortened." + $descriptionShortened = $Description.substring(0, [System.Math]::Min($AllowedLength, $Description.Length)) + return $descriptionShortened + } + else { + return $Description } } @@ -525,6 +525,11 @@ function Get-TopdeskIdentifier { $result = $responseGet | Where-object $SearchAttribute -eq $Value + if ($class -eq 'SubCategory' -and ($result | Measure-Object).Count -gt 1) { + # Ensure category ID is available or adjust order of operations to guarantee its presence + $result = $result | Where-Object { $_.Category.Id -eq $RequestObject.category.id } + } + # When attribute $Class with $Value is not found in Topdesk if ([string]::IsNullOrEmpty($result.id)) { $errorMessage = "Class [$Class] with SearchAttribute [$SearchAttribute] with value [$Value] isn't found in Topdesk" @@ -740,14 +745,12 @@ try { Description = $requestShort AllowedLength = 80 AttributeName = 'requestShort' - id = $pref.id + id = $pRef.id } - - Confirm-Description @splatParamsValidateRequestShort # Add value to request object $requestObject += @{ - briefDescription = $requestShort + briefDescription = Confirm-Description @splatParamsValidateRequestShort } # Resolve variables in the RequestDescription field diff --git a/permissions/incident/revokePermission.ps1 b/permissions/incident/revokePermission.ps1 index 916b9c2..e18dbb3 100644 --- a/permissions/incident/revokePermission.ps1 +++ b/permissions/incident/revokePermission.ps1 @@ -226,12 +226,12 @@ function Confirm-Description { $AllowedLength ) if ($Description.Length -gt $AllowedLength) { - $errorMessage = "Could not revoke TOPdesk entitlement [$id]: The attribute [$AttributeName] exceeds the max amount of [$AllowedLength] characters. Please shorten the value for this attribute in the JSON file. Value: [$Description]" - - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = $errorMessage - IsError = $true - }) + Write-Information "Attribute [$AttributeName] exceeds [$AllowedLength] characters [$Description] and will be shortened." + $descriptionShortened = $Description.substring(0, [System.Math]::Min($AllowedLength, $Description.Length)) + return $descriptionShortened + } + else { + return $Description } } @@ -525,6 +525,11 @@ function Get-TopdeskIdentifier { $result = $responseGet | Where-object $SearchAttribute -eq $Value + if ($class -eq 'SubCategory' -and ($result | Measure-Object).Count -gt 1) { + # Ensure category ID is available or adjust order of operations to guarantee its presence + $result = $result | Where-Object { $_.Category.Id -eq $RequestObject.category.id } + } + # When attribute $Class with $Value is not found in Topdesk if ([string]::IsNullOrEmpty($result.id)) { $errorMessage = "Class [$Class] with SearchAttribute [$SearchAttribute] with value [$Value] isn't found in Topdesk" @@ -740,14 +745,12 @@ try { Description = $requestShort AllowedLength = 80 AttributeName = 'requestShort' - id = $pref.id + id = $pRef.id } - - Confirm-Description @splatParamsValidateRequestShort # Add value to request object $requestObject += @{ - briefDescription = $requestShort + briefDescription = Confirm-Description @splatParamsValidateRequestShort } # Resolve variables in the RequestDescription field diff --git a/update.ps1 b/update.ps1 index 07f7db7..4eec746 100644 --- a/update.ps1 +++ b/update.ps1 @@ -161,9 +161,6 @@ function Get-TopdeskDepartment { [ValidateNotNullOrEmpty()] $LookupErrorHrDepartment, - [ValidateNotNullOrEmpty()] - $LookupErrorTopdesk, - [ValidateNotNullOrEmpty()] [Object] [ref]$Account @@ -205,19 +202,10 @@ function Get-TopdeskDepartment { # When department is not found in Topdesk if ([string]::IsNullOrEmpty($department.id)) { - if ([System.Convert]::ToBoolean($LookupErrorTopdesk)) { - # True, no department found = throw error - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = "Department [$($Account.department.name)] not found in Topdesk and the connector is configured to stop when this happens." - IsError = $true - }) - } - else { - # False, no department found = remove department field (leave empty on creation or keep current value on update) - $Account.department.PSObject.Properties.Remove('name') - $Account.PSObject.Properties.Remove('department') - Write-Information "Not overwriting or setting department as it can't be found in Topdesk. (lookupErrorTopdesk = False)" - } + $outputContext.AuditLogs.Add([PSCustomObject]@{ + Message = "Department [$($Account.department.name)] not found in Topdesk and the connector is configured to stop when this happens." + IsError = $true + }) } else { # Department is found in Topdesk, set in Topdesk @@ -240,9 +228,6 @@ function Get-TopdeskBudgetHolder { [ValidateNotNullOrEmpty()] $LookupErrorHrBudgetHolder, - [ValidateNotNullOrEmpty()] - $LookupErrorTopdesk, - [ValidateNotNullOrEmpty()] [Object] [ref]$Account @@ -286,19 +271,10 @@ function Get-TopdeskBudgetHolder { # When budgetholder is not found in Topdesk if ([string]::IsNullOrEmpty($budgetHolder.id)) { - if ([System.Convert]::ToBoolean($lookupErrorTopdesk)) { - # True, no budgetholder found = throw error - $outputContext.AuditLogs.Add([PSCustomObject]@{ - Message = "Budgetholder [$($Account.budgetHolder.name)] not found in Topdesk and the connector is configured to stop when this happens." - IsError = $true - }) - } - else { - # False, no budgetholder found = remove budgetholder field (leave empty on creation or keep current value on update) - $Account.budgetHolder.PSObject.Properties.Remove('name') - $Account.PSObject.Properties.Remove('budgetHolder') - Write-Information "Not overwriting or setting budgetholder as it can't be found in Topdesk. (lookupErrorTopdesk = False)" - } + $outputContext.AuditLogs.Add([PSCustomObject]@{ + Message = "Budgetholder [$($Account.budgetHolder.name)] not found in Topdesk and the connector is configured to stop when this happens." + IsError = $true + }) } else { # Budgetholder is found in Topdesk, set in Topdesk @@ -634,13 +610,18 @@ try { } $authHeaders = Set-AuthorizationHeaders @splatParamsAuthorizationHeaders - # Resolve branch id - $splatParamsBranch = @{ - Account = [ref]$account - Headers = $authHeaders - BaseUrl = $actionContext.Configuration.baseUrl + if ($Account.branch.PSObject.Properties.Name -Contains 'name') { + # Resolve branch id + $splatParamsBranch = @{ + Account = [ref]$account + Headers = $authHeaders + BaseUrl = $actionContext.Configuration.baseUrl + } + Get-TopdeskBranch @splatParamsBranch + } + else { + Write-Information "Mapping of [branch.name] is missing to lookup the branch in Topdesk. Action skipped" } - Get-TopdeskBranch @splatParamsBranch if ($Account.department.PSObject.Properties.Name -Contains 'name') { # Resolve department id @@ -649,7 +630,6 @@ try { Headers = $authHeaders BaseUrl = $actionContext.Configuration.baseUrl LookupErrorHrDepartment = $actionContext.Configuration.lookupErrorHrDepartment - LookupErrorTopdesk = $actionContext.Configuration.lookupErrorTopdesk } Get-TopdeskDepartment @splatParamsDepartment } @@ -664,7 +644,6 @@ try { Headers = $authHeaders BaseUrl = $actionContext.Configuration.baseUrl lookupErrorHrBudgetHolder = $actionContext.Configuration.lookupErrorHrBudgetHolder - lookupErrorTopdesk = $actionContext.Configuration.lookupErrorTopdesk } Get-TopdeskBudgetholder @splatParamsBudgetHolder }