Forums

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

Copy Jira Custom Field value to Jira Roadmaps "Team" Field

Luis Tellado March 27, 2022

Using Jira Software DC 8.21.1 with Jira Advance Roadmaps and ScriptRunner DC 6.47.0, I'm trying to auto copy a Jira custom field of "IT Team" to Jira Roadmaps "Team" field when ever the Jira custom field "IT Team" gets updated. I was thinking of using Behaviors to keep both fields in sync at all times, but it seems that this "Team" field for Jira Roadmaps only accepts value IDs.

What is the best way to copy the field value once the Jira Custom Field of "IT Team" is selected as "Fun Team1", which needs to copy the equivalate field value ID of "11" to the Jira Roadmaps field "Team" which only accepts IDs? I'm looking for help with the groovy script that would address this with Behaviors.

Appreciating You!

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 27, 2022

Hi @Luis Tellado

It would be better to use the Listener for your requirement instead of the Behaviour.

Could you please provide more information, i.e. what type of field are you using for IT Team?

Thank you and Kind regards,

Ram

Luis Tellado March 27, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

That would make sense since I can use Issue Created and Issue Updated events to trigger the script that I need help with. I'm using a Select List (multiple choices) for the "IT Team" field. Please Note: their would normally only be one team/value selected. The reason its multi-select is for Features Epics that span multiple teams.

Appreciating You and Thanks!

Luis

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 7, 2022

Hi @Luis Tellado

For your requirement, you could try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager

def sampleMultiSelect = customFieldManager.getCustomFieldObjectsByName('Sample Multi Select').first()
def sampleMultiSelectValue = sampleMultiSelect.getValue(issue) as String

def selectedOption = customFieldManager.getCustomFieldObjectsByName('Selected Option').first()

issue.setCustomFieldValue(selectedOption, sampleMultiSelectValue)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

Please note that the sample working code above is not 100% exact to your environment. Hence you will need to make the required modifications. 

You will need to use the Custom Listener and set the IssueCreated and IssueUpdated events for the Listener configuration.

Below is a print screen of the Listener configuration:-

listener_config.png

The Issue Created event and Issue Updated event have been selected in this example. So the listener will trigger during the creation of an Issue and when the Issue is edited. 

Below are a few test print screens for your reference:-

1. In the first test, a ticket is created, but no option has been selected in the Sample Multi Select field. Hence, no value is displayed on the Issue when it is first created, as shown in the image below.

image1.png

Similarly, there is no value added to the Selected Options field in the Roadmap.

image2.png

2. Next, the Issue is updated, and an option is selected from the Sample Multi Select list, as shown in the image below.image3.png

Accordingly, the field is now visible in the ticket. Also, the Selected Options field is visible.

image4.png

Finally, if you now check the Roadmaps page, it will display the updated value for the Selected Options field.

image5.png

I hope this helps to solve your question. :)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer