Scripted Field - Copy Fix Version from Linked Issue

Fairly self-explanatory but all the Questions on Community revolve around custom fields and/or calculating Estimates for the same based on Links. I just want to very simply pull the Fix Version of the Linked Issue (based on Link Type) and copy it into this Scripted Field. 

Keeps displaying an error though, regardless of whether I choose the Custom or Text templates.

Code and screenshot below.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comparator.VersionComparator
import com.atlassian.jira.project.version.Version

def issue = issue as Issue

def fixVersionsInIssues = [] as List<Version>
def comparator = new VersionComparator()

ComponentAccessor.getIssueLinkManager().
    getOutwardLinks(issue.id)?.
    findAll {it.issueLinkType.name == "Base"}?.
    each {it -> fixVersionsInIssues.addAll(it.destinationObject?.fixVersions) }

fixVersionsInIssues?.max(comparator)?.name

 

startupfail.PNG

2 answers

0 vote

The "each" line is not valid code.  You need a -> after the it, not a control sequence.

Oh you are so right about the line in so much that it looks like an ASCII translation in pasting.

Still doesn't solve the issue though, coming up blank still. I'm taking this directly from another Adaptavist code block that line.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comparator.VersionComparator
import com.atlassian.jira.project.version.Version

def issue = issue as Issue

def fixVersionsInIssues = [] as List<Version>
def comparator = new VersionComparator()

ComponentAccessor.getIssueLinkManager().
    getOutwardLinks(issue.id)?.
    findAll {it.issueLinkType.name == "Base"}?.
    each {it -> fixVersionsInIssues.addAll(it.destinationObject?.fixVersions) }

fixVersionsInIssues?.max(comparator)?.name

Ok, I think you need a return on last line.

I note it's scanning for many links and just grabbing one of them to give you.  I'm not sure what the comparator will return there.

From what I understand of the original question and its response, the intent was to get the latest fixVersion, I believe. That doesn't apply to me since I have another script in place for limiting the field to 1 value, but I kept it in there because it can't hurt (I thought).

And I have a return on the other code and that doesn't work either. See my other question about Scripted Fields submitted today.

 

I put in to return the fixVersionInIssues but no dice. Same blank as before.

Yes, I thought I should check, in case you were expecting something else.

My next thought - I don't think it.issueLinkType.name is a valid call, I think it should be it.issueLinkType.getName()

One other thought too - when these scripts chuck errors out, they go into the log, usually with a lot more information (for example, if I'm right about the getName, your code would be throwing something like "unknown property: name" when it hits it).  When I'm using a preview to check a scripted field, I tend to be tailing the log alongside it.

The log is showing as completely null.

 

I changed to it.issueLinkType.getName() and the same [] Output and Null in log.

:( 

Shouldn't it be:

it.destinationObject.issueTypeObject.name == "Base"

Well, I am not picking up the issue type, I'm picking up the link type. We don't have an issue type of Base :) 

Nic, do you have any other ideas? The log is null and so is the preview...

That suggests it's not finding any links there.  Have you tried logging to see the execution flow?

Everything is null. Logging, output... It's happening for both this as well as my other question, which Daniel has been looking into. 

If you put a System.out.println("Debug me") line into it somewhere, you are guaranteed a line in the log.  Could you try that?

If that doesn't come out, then you've disabled *all* the logging somehow, and your log will only have a bit of startup data in it.

Adding just that line to the original code body does nothing.

Doing below throws a generic error. 2017-07-17 16:15:33,851 DEBUG [customfield.GroovyCustomField]: fixVersionsInIssues

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comparator.VersionComparator
import com.atlassian.jira.project.version.Version
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issue = issue as Issue

def fixVersionsInIssues = [] as List<Version>
def comparator = new VersionComparator()

ComponentAccessor.getIssueLinkManager().
getOutwardLinks(issue.id)?.
findAll {it.issueLinkType.getName() == "Base"}?.
each {it -> fixVersionsInIssues.addAll(it.destinationObject.fixVersions) }

fixVersionsInIssues?.max(comparator)?.name

log.setLevel(Level.DEBUG)
log.debug "fixVersionsInIssues"

 Now I have this in the Atlassian-JIRA log:

2017-07-17 16:23:43,112 http-bio-443-exec-1311 DEBUG James.Lee 983x1130694x1 u8lgj9 10.255.250.126,10.255.249.199 /secure/AjaxIssueAction!default.jspa [c.o.scriptrunner.customfield.GroovyCustomField] fixVersionsInIssues

 

So it can't be getting that far through the script - that line should be in the atlassian-jira.log if it got that far into it.

Any suggestions on how to debug?

@Daniel Yelamos [Adaptavist] 

@Adam Markham [Adaptavist]

 
 

Any ideas on this, or any of your team have any ideas? Between this and the Base Status not coming over, I'm getting really frustrated :( 

 

 

Hi Lacey, 

I understand your frustration. I've posted an example for getting the base status along with an explanation on your other question here.

Hopefully that will clarify things for you. You should then be able to adapt this script for the fix versions using the same example.

However if your still having issues just let us know and we'll help.

Thanks,
Adam

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

125 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you