From 16604f36a0a1e0e684efdd5144cb738adbe13c1e Mon Sep 17 00:00:00 2001 From: Piotr Baran Date: Fri, 19 May 2023 11:57:28 +0200 Subject: [PATCH] Allow fields to be filtered by id only --- JiraPS/Public/Get-JiraField.ps1 | 24 +++++++++++++++++++++++- JiraPS/Public/Set-JiraIssue.ps1 | 6 +++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/JiraPS/Public/Get-JiraField.ps1 b/JiraPS/Public/Get-JiraField.ps1 index 589440e6..ce0e28aa 100644 --- a/JiraPS/Public/Get-JiraField.ps1 +++ b/JiraPS/Public/Get-JiraField.ps1 @@ -6,6 +6,14 @@ function Get-JiraField { [String[]] $Field, + [Parameter] + [Switch] + $filterByName, + + [Parameter] + [Switch] + $filterById, + [Parameter()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] @@ -43,7 +51,21 @@ function Get-JiraField { $allFields = Get-JiraField -Credential $Credential - Write-Output ($allFields | Where-Object -FilterScript { ($_.Id -eq $_field) -or ($_.Name -like $_field) }) + Write-Output ($allFields | Where-Object -FilterScript { + if (($filterByName -and $filterById) -or (-not $filterByName -and -not $filterById)) + { + ($_.Id -eq $_field) -or ($_.Name -like $_field) + + } + elseif ($filterByName) + { + ($_.Name -like $_field) + } + elseif ($filterById) + { + ($_.Id -eq $_field) + } + }) } } } diff --git a/JiraPS/Public/Set-JiraIssue.ps1 b/JiraPS/Public/Set-JiraIssue.ps1 index 33d6f633..835ed19b 100644 --- a/JiraPS/Public/Set-JiraIssue.ps1 +++ b/JiraPS/Public/Set-JiraIssue.ps1 @@ -47,6 +47,10 @@ function Set-JiraIssue { [PSCustomObject] $Fields, + #this is to fix case when there are multiple fields of the same name + [PSCustomObject] + $filterFieldsById, + [String] $AddComment, @@ -162,7 +166,7 @@ function Set-JiraIssue { $name = $_key $value = $Fields.$_key - $field = Get-JiraField -Field $name -Credential $Credential -ErrorAction Stop + $field = Get-JiraField -Field $name -Credential $Credential -filterById:$filterFieldsById -ErrorAction Stop # For some reason, this was coming through as a hashtable instead of a String, # which was causing ConvertTo-Json to crash later.