Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: JIRA::Client returns blessed hash

by keszler (Priest)
on Dec 10, 2011 at 18:33 UTC ( [id://942853]=note: print w/replies, xml ) Need Help??


in reply to Re^2: JIRA::Client returns blessed hash
in thread JIRA::Client returns blessed hash

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.

Replies are listed 'Best First'.
Re^4: JIRA::Client returns blessed hash
by perlPractioner (Novice) on Dec 10, 2011 at 19:23 UTC

    Thanks for the response keszler. I initially got the error stating that the setFilterIterator should be called before calling nextIssue. So, I included the set_filter_iterator on the filterID. The code looks like this:

    15 my $jira=JIRA::Client->new('http://example.com/jira',$user,$pw); 16 $jira->set_filter_iterator($filterID); 17 18 my %custom_fields = $jira->get_custom_fields(); 19 my @custom_field_names = keys %custom_fields; 20 # if the above is filled with IDs instead of names, use 'values' in +stead of 'keys' 21 22 23 while (my $issue = $jira->next_issue()) { 24 25 print 'Priority: ', $issue->getPriority, "\n"; 26 print 'Status : ', $issue->getStatus, "\n"; 27 28 my @custom_field_values = $jira->get_issue_custom_field_values($i +ssue, @custom_field_names); 29 30 for (my $i=0; $i < @custom_field_names; $i++) { 31 print "Custom Field $custom_field_names[$i] : $custom_field_val +ues[$i]; 32 } 33 print '-'x40,$/; 34 }

    So now I am getting the following 2 errors when running the above code: 1) Reference found where even-sized list expected at test.pl line 18. 2) Can't locate object method "getPriority" via package "RemoteIssue" at test.pl line 25. For error #1, this might have been caused because the hash "customFieldValues" is using a "[]" instead of a "()" to assign the other sub-blessed hashes. Not quite sure on that though. For error #2, not sure why this is being generated since the "RemoteIssue" e.g. status, is part of $VAR1; which should assign a priority of 2 to all the sub-hashes.

      Looks like I guessed wrong on get_custom_fields returning a hash instead of a hash reference.

      18 my $custom_fields_ref = $jira->get_custom_fields(); 19 my @custom_field_names = keys %{$custom_fields_ref};
      should fix that.

      I had found a reference to http://docs.atlassian.com/rpc-jira-plugin/4.1-1/com/atlassian/jira/rpc/soap/beans/RemoteIssue.html, with a statement that the Perl module replicated the Java methods. One of these might work:

      $issue->getpriority $issue->get_priority $jira->getpriority($issue) $jira->get_priority($issue) $issue->{priority} # this may work, but is less desirable than using +a method

        Seems like we are making progress :) . Here is what the code looks like now:

        15 my $jira=JIRA::Client->new('http://example.com/jira',$user,$pw); 16 $jira->set_filter_iterator($filterID); 17 my @custom_field_names; 18 my $custom_fields_ref = $jira->get_custom_fields(); 19 my @custom_field_names = keys %{$custom_fields_ref}; 20 # if the above is filled with IDs instead of names, use 'values' in +stead of 'keys' 21 22 23 while (my $issue = $jira->next_issue()) { 24 25 print 'Priority: ', $jira->get_priorities($issue), "\n"; 26 print 'Status : ', $jira->get_statuses($issue), "\n"; 27 my @custom_field_values; 28 @custom_field_values = $jira->get_issue_custom_field_values($issue, + @custom_field_names); 29 30 for (my $i=0; $i < @custom_field_names; $i++) { 31 print "Custom Field $custom_field_names[$i] : $custom_field_val +ues[$i]; 32 } 33 print '-'x40,$/; 34 }

        The issue is I am getting back "Prioritity: HASH(0x******)" and the same for the Status. Not sure why this is the case because I am using Dumper on both of these calls. It is also interesting that most of the custom field values (@custom_field_values) are missing. The ones that are being shown are displayed as "ARRAY(0x******)". I am also wondering if the custom field names that are returned are for this particular filterID because they are not displayed on the actual JIRA filter page and most of their values are missing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://942853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-16 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found