Copy Issue Picker value(s) to Linked Issue Field

Richard Duffy June 19, 2019

Hi All

Goal: To limit what issue types a user can link my "Feature" issue type too.

Looking for some help, Open to all suggestions. I have scriptrunner & JSU plugins.

I have a scripted field (Issue picker searcher type) called "Link your Issue" on the create screen. The issues available are limited to JQL search.

I now need to copy this value to the Linked Issue field. I have made the field read only and pre-set the link type using a behavior. I dont mind if the value is copied on the create screen using form values or after its created using a post function.

Or I could also have a workflow validator to limit the issue types users can link too

Any help much appreciated

Thanks

Richard 

2 answers

1 accepted

3 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 20, 2019

Using behavior is probably the simplest here.

Add the following  server side script on your "Link your issue" field:

def linkedIssuesFld = getFieldById("issuelinks-issues")
def linkInputFld = getFieldById(getFieldChanged())

def inputIssue = linkInputFld.value
if(inputIssue){
linkedIssueFld.setFormValue(inputIssue)
}
Richard Duffy June 20, 2019

Thanks for your quick reply, that works perfectly. Simple and effective! 

Pawel Ogrodnik November 14, 2019

@Peter-Dave Sheehan That is great, how to do it with duble issue picker, now if I Have 2 and i select second  issue picker, cleared first and write the second one.

I need 2 link

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2019

I think you can just grab the existing value first then add to it as an array.

def linkedIssuesFld = getFieldById("issuelinks-issues")
def linkInputFld = getFieldById(getFieldChanged())

def inputIssue = linkInputFld.value
if(inputIssue){
def linkedIssues = linkedIssueFld.formValue
if(linkedIssues instanceof String){
//if there is only one linked issue, it will be a simple String, we convert to ArrayList with the new value
linkedIssues = [linkedIssues,inputIssue]
} else {
//if there are more than one, it will already be an ArrayList, we just add to it
linkedIssues << inputIssue
}
linkedIssueFld.setFormValue(linkedIssues )
}
Like # people like this
Pawel Ogrodnik November 14, 2019

Thanks for quick answer ,

Works if it fills in the right order :)

Thanks a lot

Anuradha kumari July 29, 2020

Where need to add these script

Richard Duffy July 29, 2020

@Anuradha kumari  these are behaviour scripts on scriptrunner for jira

Anuradha Yadav September 7, 2022

Hi, @Richard Duffy @Peter-Dave Sheehan 

Could you please help? I added the same script but seeing the below error.

image.png

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2022

There was a typo in the first response.

Make sure the declared variables in line 1 is spelled the same as the variable used in line 6

def linkedIssuesFld = getFieldById("issuelinks-issues")
def linkInputFld = getFieldById(getFieldChanged())

def inputIssue = linkInputFld.value
if(inputIssue){
linkedIssuesFld.setFormValue(inputIssue)
}
Anuradha Yadav September 7, 2022

Hi @Peter-Dave Sheehan , Yes I got that, But the filed value is not copying for me.

for Example: 

  1.  my Epic 'DESP-2'
  2.  is my Feature 'DESART-3'

Now I want to Copy the value of  "STRATEGIC" field (Single Link picker) from Epic to Feature..

Needed: When STRATEGIC field is updated in EPIC the same value should be copied to STRATEGIC field in Feature and should be read-only

 

This is my setup in Behaviour Peter, Could you please help me here?

 

image.png

image.png

0 votes
Oliver Schalch October 5, 2022

Hi, 

Is there also a way to debug this, in the behavior settings there is nothing like "if the script was run" - i impleted on my side - but nothing happens, or the issue dont get a new linked issue from the selected issue picket issue.

Thanks

Oli

Suggest an answer

Log in or Sign up to answer