Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

JIRA::Client returns blessed hash

by perlPractioner (Novice)
on Dec 10, 2011 at 17:37 UTC ( #942842=perlquestion: print w/ replies, xml ) Need Help??
perlPractioner has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, this post is in reference to one of my previous posts from last week here. Since I only have a chance to work on this over the weekends, my repsonse is a bit delayed. I am using JIRA::Client to retrieve the issues from a JIRA filter. The issues are returned as a blessed hash resembling the following:

$VAR1=bless( { 'priority' => '2', 'customFieldValues' => [ bless( { 'customfieldID' => 'cus +tomfield_12345', 'values' => ['John Smit +h'], 'key' => undef}, 'RemoteCustomFieldValue +' ), bless( { 'customfieldID' => 'cus +tomfield_abcde', 'values' => ['Californi +a'], 'key' => undef}, 'RemoteCustomFieldValue +' )], 'status' => 'Completed' }, 'RemoteIssue'); $VAR1=bless( { 'priority' => '2', 'customFieldValues' => [ bless( { 'customfieldID' => 'cus +tomfield_12345', 'values' => ['Mary Monr +oe], 'key' => undef}, 'RemoteCustomFieldValue +' ), bless( { 'customfieldID' => 'cus +tomfield_abcde', 'values' => ['New York' +], 'key' => undef}, 'RemoteCustomFieldValue +' )], 'status' => 'In progress' }, 'RemoteIssue');

Each issue is returned as $VAR1 with priority set to '2'. Within each issue, there are custom fields ('RemoteCustomFieldValue') such as the client's name and their state. I know the customfieldIDs that reference each name and state. There is also a non-custom field ('RemoteIssue') such as the issue status. I am not too familiar with iterating through hashes/sub-hashes, but for every $VAR1 in this hash, I need the 'values' of each customfieldId (which I already know). So for example, to get the client's name for each issue, I need to get the value where customfieldId is 'customfield_12345'. Also, for each issue I am trying to get the status, which is a 'RemoteIssue' and not a 'RemoteCustomFieldIssue'. From this hash, I am trying to create a table which looks like this:

Name State Status
John Smith California Completed
Mary Monroe New York In Progress

The code I have so far that generates the blessed hash from above is shown below. Any suggestions would greatly be appreciated. Thanks in advance monks.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use LWP::UserAgent; use JIRA::Client; use SOAP::Lite; my $user = 'username'; my $pw = 'password'; my $filterID = '12345'; my $jira=JIRA::Client->new('http://example.com/jira',$user,$pw); $jira->set_filter_iterator('$filterID'); while (my $issue = $jira->next_issue()) { my $value = Dumper($issue); print $value; }

Comment on JIRA::Client returns blessed hash
Select or Download Code
Replies are listed 'Best First'.
Re: JIRA::Client returns blessed hash
by keszler (Priest) on Dec 10, 2011 at 17:46 UTC

    Did you try my suggestion from last week?

    while (my $issue = $jira->next_issue()) { #print Dumper($issue); my $custom_fields_ref = $issue->get_custom_fields(); for my $cf_name (keys %{$custom_fields_ref}) { print ">>$cf_name<< = >>>$custom_fields_ref->{$cf_name}<<<\n"; } print 'Priority: ', $issue->priority, $/; # do as above for other fields at the same level as 'priority' => 2 }

      Yes I tried that. But when I ran it I am getting the following error: "Can't locate object method "get_custom_fields" via package "RemoteIssue" at test.pl line 22." I am guessing that this is because the blessed hash returned contains both custom fields ("RemoteCustomFieldValue") and non-custom fields ("RemoteIssue"), e.g. status. Applying the "get_custom_fields" method on a hash that is not a custom field seems to be the root cause of this error. Not sure if there is a way to apply that method to just the "RemoteCustomFieldValue" hashes.

        Ah - I think I see. Try:

        my $jira=JIRA::Client->new('http://example.com/jira',$user,$pw); my %custom_fields = $jira->get_custom_fields(); my @custom_field_names = keys %custom_fields; # if the above is filled with IDs instead of names, use 'values' inste +ad of 'keys' while (my $issue = $jira->next_issue()) { print 'Priority: ', $issue->getPriority, "\n"; print 'Status : ', $issue->getStatus, "\n"; my @custom_field_values = $jira->get_issue_custom_field_values($issu +e, @custom_field_names); for (my $i=0; $i < @custom_field_names; $i++) { print "Custom Field $custom_field_names[$i] : $custom_field_values +[$i]; } print '-'x40,$/; }
        Incidentally, RemoteIssue is the class that $issue is blessed as.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://942842]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2015-07-30 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls