Parsing Custom field of type "Version Picker"

Deleted user April 23, 2015

I'm pulling JIRA data into my database using a Perl script to create csv files, which are then imported to the database. While I'm able to pull in the "affectsVersions" and "fixVersions", I'm having trouble pulling in just the displayed string for a custom field of the same type, "Version Picker". (It's custom field number "10780" below).

Here's the related snippets...

sub getSingularObjectFromString($$);

print(getVersions($issue->{affectsVersions}) . $DELIM); # gets displayed contents
print(getVersions($issue->{fixVersions}) . $DELIM); # gets displayed contents
print(getSingularObjectFromString($issue, 10780) . $DELIM); # Trying to get just the "displayed" contents

 

...for "affects versions" and "fixVersions" I can just pull the data by using "getVersions"...

sub getVersions {

my ($versions) = @_;

my $str;

return "" if (scalar(@$versions) == 0);

foreach my $version (@$versions) {
if ($str) {
$str .= ", " . $version->{name};
} else {
$str = $version->{name};
}
}

return $str;
}

...but since "testVersions" is a custom field  (of the same type as the others), I'm trying to get just the displayed/rendered value that appears.

 

# Trying to get just the "displayed" contents of the "test version" custom field. Tried several variations here...

 

sub getSingularObjectFromString($$) {

my ($issue, $fieldID) = @_;

my $customFields = $issue->{customFieldValues};

return "" if (scalar(@$customFields) == 0);

foreach my $customField (@$customFields) {

if ($customField->{customfieldId} eq "customfield_$fieldID") {
return $customField->{values};
}
}

return "";
}

 

...My scripts work fine and pull a version number (such as "4.3.2.1") for both "affectsVersions" and "fixVersions", but for the custom field it seems to be pulling a number that JIRA uses as a reference to those versions, so I get something like "23591" instead of "4.3.2.1". Am I missing something? I've tried these methods and a few more...

getValueFromIssue

getExternalFieldValue

getSingularObjectFromString

getCustomFieldValue

All of these pull the "number" from the custom field, not the displayed value.

Is there a way to get the displayed Test Versions of "4.3.2.1" that is displayed when the issue is viewed in JIRA? Any insight would be helpful. Thanks!

 

1 answer

0 votes
Deleted user April 24, 2015

Let me summarize with an example. I have a fixVersion that displays "4.3.21.4" on the JIRA issue screen. I also have a Tested Version that also displays "4.3.21.4" on that same issue. Both of these reference (internally, in JIRA) a "number". For this example that number is "23303". When I try to pull the values from these JIRA fields, I get "4.3.21.4" for the fixVersion, but "23303" for the Tested Version. How do I get the value that is being displayed by JIRA for my custom field, instead of the number 23303?

Chris Henry February 26, 2019

I have a similar situation, did you ever find a solution?

Chris Annal February 26, 2019

Hi Chris,

As a matter-of-fact, I did resolve this on my own, after a LOT of trial-and-error. Here's the blocks of code I added for the "Version.Picker" custom field type. Note that "customfield_10780" should be replaced by the custom field number used by your custom version picker field.

"sheet1.write..." is referring to the Excel spreadsheet that I was importing the results into.

#
###################################################################
#
# "test versions" field : Getting just the "name" part of this field -
customfield_10780 = ""
release = ""
# CUSTOM FIELDS OF TYPE "Version Picker" require "...or []" to handle TypeError: 'NoneType' object is not iterable" error
for version in myissue.fields.customfield_10780 or []:
release = version.name
if customfield_10780 == "":
customfield_10780 = release
else:
customfield_10780 = versions + ", " + release
get_names = []
for name in customfield_10780:
get_names.append(name)
release = get_names
sheet1.write(row,14, str(release)) # REQUIRES the above "for version in myissue.fields.fixVersions..."..

 

Chris Annal February 26, 2019

Hi Chris,

I hope I'm not duplicating myself. I posted a Reply but it didn't show up. Anyway, here's how I resolved it for the Version.Picker field. Note that "customfield_10780" would be replaced by whatever the custom field of type "Version.Picker" is in your JIRA....

# "test versions" field : Getting just the "name" part of this field - 
customfield_10780 = ""
release = ""
# CUSTOM FIELDS OF TYPE "Version Picker" require "...or []" to handle TypeError: 'NoneType' object is not iterable" error
for version in myissue.fields.customfield_10780 or []:
release = version.name
if customfield_10780 == "":
customfield_10780 = release
else:
customfield_10780 = versions + ", " + release
get_names = []
for name in customfield_10780:
get_names.append(name)
release = get_names
sheet1.write(row,14, str(release))  

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events