Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help copying a fix version field value to linked issues using scriptrunner listener

Eric Sebian
Contributor
June 10, 2020

I am slowly learning groovy and scriptrunner. I Need help copying a fix version field value to linked issues using scriptrunner listener. I found solutions using post function scripts but nothing for the listener. I have done various searches on the web as well as searched the Adaptavist library but have found nothing. Their support Please advise

1 answer

0 votes
Nic Brough -Adaptavist-
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.
June 11, 2020
Eric Sebian
Contributor
June 12, 2020

Hi Nic. is there a service that your company provides that I can purchase to walk me thru creating a particular script? Maybe someone in the company who'd be willing to freelance for a fee. I'd be paying personally so it couldn't be exorbitant. I'm great at managing jira projects but coding related tasks go over my head every time. I'm better at learning thru real world applications. Hope that makes sense.

Eric Sebian
Contributor
June 13, 2020

Also, when i plug in the code from the link that you suggest above into a custom listener, it's riddled with errors. It's hard to start to figure out how to tweak it when it doesnt seem to be a working listener script. See image. Screen Shot 2020-06-14 at 12.02.59 AM.png

Eric Sebian
Contributor
July 6, 2020

Ok, Nic. Based on your advice I hunted and pecked and cobbled together a script that seems SHOULD work. Unfortunately, it doesn't. Referencing the script that you suggested and a host of others I got the following: 

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.onresolve")
log.setLevel(Level.INFO)

def issue = event.issue

if(issue.issueType.name == "Epic") {
log.info "*****Issue $issue is a EPIC"
def projectKey = issue.projectObject.key;

def change = event.getChangeLog().getRelated("ChildChangeItem").find {it.field == "Fix Version"}
log.info "*****Issue $issue change = $change"
//def change_issue = issue?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Fix Version/s"}
//logs.info "*****change_issue = $change_issue"
def issueLinkManager = ComponentAccessor.issueLinkManager;
def issueManager = ComponentAccessor.issueManager;

if(change) {
issueLinkManager.getOutwardLinks(issue.getId()).each {IssueLink issueLink ->
if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
log.info "*****Issue $issue is a Epic-story link"
def destinationIssue = (MutableIssue)issueLink.getDestinationObject();
if(destinationIssue.projectObject.key.equals(projectKey)) {

destinationIssue.setFixVersions(issue.fixVersions)
log.info "*****setting up fixVersions $issue.fixVersions"
issueManager.updateIssue(event.getUser(), destinationIssue, EventDispatchOption.DO_NOT_DISPATCH, false)

}
}
}
}
}

 

i added logging info at different points to determine how far it's getting. So in the logs I see that it gets past identifying that the issue is an EPIC:

2020-07-06 23:32:17,159 http-nio-8080-exec-50 INFO Eric.Sebian@JCrew.Com 1412x6763879x1 ve7ttp 69.20.50.84,198.143.37.19,10.200.8.60,10.200.88.9 /secure/AjaxIssueAction.jspa [com.onresolve] *****Issue AWNEP-54 is a EPIC

and then, after I define the change the logs show that the fix version change is identified but the changelog is missing information:

2020-07-06 23:32:17,161 http-nio-8080-exec-50 INFO Eric.Sebian@JCrew.Com 1412x6763879x1 ve7ttp 69.20.50.84,198.143.37.19,10.200.8.60,10.200.88.9 /secure/AjaxIssueAction.jspa [com.onresolve] *****Issue AWNEP-54 change = [newvalue:null, field:Fix Version, oldstring:test version 3, newstring:null, id:4498125, fieldtype:jira, oldvalue:32426, group:2825840]

new string continually comes back Null. this should not be because I changed it from test version 3 to test version 1.

It also never finds the linked issue connectedto update. See image.

 

Please advise.

Eric Sebian
Contributor
July 6, 2020

2020-07-06_23-49-50.jpg

Nic Brough -Adaptavist-
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.
July 7, 2020

Sorry, going back a couple of comments:

If the line

def issue = event.issue

is not working, then it implies that you are not putting the script in a listener. 

Listeners provide an event object to them (but you might not be working in the context of something that happens to an issue).  If you're in a post-function (which do have a lot in common with listeners) or a condition or validator, there is no event, but you are running within an issue context, so you can just use the issue object directly.

In the second script, it looks like newstring is null because you're setting the fix version to empty - deleting it, not changing it to version 1

Eric Sebian
Contributor
July 7, 2020

I've resolved the def issue = issue event. Turns out that the listener console shows an error on that line until you save it.

As far as your 2nd statement, do you mean in the code? Because on the issue I'm just changing the version from Test version 3 to Test version 1. 

and is it not finding the linked issues because it doesn't get to that step? I've been working on this for a month now and it doesn't seem that it should be this hard.

thanks.

Nic Brough -Adaptavist-
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.
July 7, 2020

Your screenshot (and returned history string) are saying that you've blanked out the version, not set it.

Eric Sebian
Contributor
July 8, 2020

please see the ticket that you commented on in 2014.

https://community.atlassian.com/t5/Jira-Questions/How-to-find-the-current-fixVersion-of-an-issue/qaq-p/369315

this is what is happening. how do I resolve this?

Nic Brough -Adaptavist-
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.
July 9, 2020

What appears to be happening here is that you're blanking out the version on the issue, not setting it to something else.  Your screenshot and history record say that's what is happening.

So I'm stuck on what you are asking now.

Eric Sebian
Contributor
July 12, 2020

I've attached images show exactly what I'm doing as well as the log below to show how the system is reacting.As you can see from the image, Test Version 1 was already there but that's not reflected in the log.

Screen Shot 2020-07-12 at 10.21.24 PM.png

 

 

2020-07-12 22:23:52,967 http-nio-8080-exec-21 INFO Eric.Sebian@JCrew.Com 1343x14033467x1 e1oc2b 165.225.38.249,198.143.38.19,10.200.8.60,10.200.88.9 /secure/AjaxIssueAction.jspa [com.onresolve] *****Issue AWNEP-57 change = [newvalue:32425, field:Fix Version, oldstring:null, newstring:test version 2, id:4509304, fieldtype:jira, oldvalue:null, group:2832821]
[root@ue1latljirasp02 log]#

Suggest an answer

Log in or Sign up to answer