Copy Affects Versions from an issue to another with scriptrunner

sylvain_t December 21, 2020

Hi,

I'm creating a behaviour in scriptrunner to copy specific fields of the current issue to a new task in another project.

I'm able to do it on all the fields I require except "Affects Versions" which is not copying anything.

Here is my script : 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()

if (getBehaviourContextId() == "create-myproject-linked-task") {
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)

def contextIssue = issueManager.getIssueObject(getContextIssueId())

getFieldById("summary").setFormValue(" support request for ${contextIssue.key}").setReadOnly(true)
getFieldById("issuelinks-linktype").setFormValue("relates to").setReadOnly(true)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
getFieldById("labels").setFormValue("Customer,Support").setReadOnly(true)
getFieldById("versions").setFormValue(contextIssue.key).setReadOnly(false)
getFieldById("description").setFormValue("Only for time tracking for L4 support. Any functional or technical analysis and comments should be tracked in related project.")
}


 As you can see the faulty line is :

getFieldById("versions").setFormValue(contextIssue.key).setReadOnly(false)

I searched a solution on internet for hours but did not find anything. I guess it has something to do with the fact that it returns a list and not a string but I can't find the proper way to make it work.

Does anybody have the solution for this?

thanks

1 answer

0 votes
Bill Sheboy
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.
December 29, 2020

Hi @sylvain_t 

In your code, you appear to be copying an Issue Key into a version field. Is that what you intended to do?

As the versions are pre-defined values for a project, I suspect that would not work unless you also created versions for all of the possible keys that could be loaded.

Best regards,

Bill

sylvain_t February 1, 2021

Hi @Bill Sheboy , thanks for the feedback.

What I want to achieve is to copy the value of the"Affects version" field into the same field for a sub-task in another project.

I could never achieve this and we are just living with it. I guess that it's indeed an issue with the "Affects version' field behavior itself, not permitting to copy a raw value but instead copying a unique ID that is not existing in the other project.

Bill Sheboy
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.
February 2, 2021

That is correct, as the versions are defined values values for each project.  That helps with change management (Fix Version) and defect impact analysis (Affects Version).

If you first create the version in the target (destination) project you can then set it.

Suggest an answer

Log in or Sign up to answer