Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I retrieve a specific value of a custom field with PowerShell?

Scott Napolitan March 9, 2022

I'm trying to retrieve a table of Jira issues using PowerShell.

I'm using the syntax below and that works for everything except the custom field, which is empty.  

$Results | Select-Object -Property summary,Key,ID,status,Project,Assignee,customfield_12300, Created, resolutiondate,duedate,resolution,labels

Furthermore, I only want the value of this field, not the entire contents (which I'm not getting anyway).

customfield_12300 : @{self=https://jiratest.corp.docusign.com/rest/api/2/customFieldOption/17903; value=Orange; id=17903; disabled=False}

Is this possible to do with PowerShell (JiraPS)?  I'm running version 2.1.6 of JiraPS.

1 answer

1 accepted

1 vote
Answer accepted
Scott Napolitan March 9, 2022

Nevermind, I figured it out on my own.  If anyone is interested, this is the syntax I used.

 

$Results | Select-Object -Property summary,Key,ID,status,Project,Assignee,Created,resolutiondate,duedate,resolution,@{Name="Team"; Expression={$_.customfield_12300.value}}
Now if I can just figure out how to expand labels so I'm not getting System.Object[] back I'll be golden!  :-)
Hugh Kelley
Contributor
May 30, 2023

This is a bit less compact than yours, but it does the name translation dynamically,

# Get a map of custom fields for translation/rename
$customFields = Get-JiraIssueCreateMetadata -Project $JiraProjectKey -IssueType 'Task' | ?{$_.Id -like "customfield_*"}

$issues = Get-JiraIssue -Query "project = '$JiraProjectKey' AND created >= -5d"

foreach($issue in $issues)
{
foreach($cf in $customFields)
{
if($issueField = $issue.psobject.Properties[$cf.Id])
{
$issue | Add-Member -NotePropertyName $cf.Name -NotePropertyValue $issueField.Value
$issue.PSObject.Properties.Remove($cf.Id)
}
}

$issue
}

Suggest an answer

Log in or Sign up to answer