http://www.perlmonks.org?node_id=942843


in reply to JIRA::Client returns blessed hash

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 }

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

    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.

        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.