Scripted Field - Copy Fix Version from Linked Issue

Lacey McDonnell July 11, 2017

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 votes
Lacey McDonnell July 31, 2017

@Daniel Yelamos [Adaptavist] 

@adammarkham

 
 

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 :( 

 

 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2017

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2017

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

Lacey McDonnell July 11, 2017

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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2017

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.

Lacey McDonnell July 11, 2017

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2017

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.

Lacey McDonnell July 12, 2017

The log is showing as completely null.

 

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

:( 

Tobias Albrecht July 13, 2017

Shouldn't it be:

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

Lacey McDonnell July 13, 2017

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 :) 

Lacey McDonnell July 17, 2017

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 17, 2017

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

Lacey McDonnell July 17, 2017

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 17, 2017

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.

Lacey McDonnell July 17, 2017

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

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 17, 2017

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.

Lacey McDonnell July 20, 2017

Any suggestions on how to debug?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events