Forums

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

Is it possible to set a select list field value when an issue is moved between 2 specific projects?

Mihai Mihai
Contributor
June 4, 2019

Hello, 

Using ScriptRunner - Listeners, we would need to add a specific value to a custom field (single select list type) when an issue is moved from one specific project to another specific project.

Example: issue ABC-1 is in project ABC. When it is moved to the project XYZ, the custom field (single select list) Team gets a certain value ("Team1"). 

 

Thank you!

1 answer

1 accepted

1 vote
Answer accepted
Andrew
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 4, 2019

Hi @Mihai Mihai ,

You can use listener for that. Look here https://community.atlassian.com/t5/Enterprise/Scriptrunner-sends-a-notification-when-opening-a-question-with-a/gpm-p/1099185#M213

In post you can see how I check new value for status. I suppose You need check new value for issue key.

You need change event for 'issue moved' and change custom field. How change value of the custom field https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Basic-method-to-update-a-custom-field-with-Scriptrunner/qaq-p/362875

B.R.

Mihai Mihai
Contributor
June 4, 2019

Hi @Andrew 

Thank you for your reply!

 

I managed to put this together:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.MutableIssue


def cfAgileTeam = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Agile Team")
def issue = event.issue as MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cfConfig = cfAgileTeam.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'Team A'
}


def changeProjectfromTPtoFCN = event.getChangeLog().getRelated("ChildChangeItem").find{ it.field == "project" && it.oldvalue == "Project A Name" && it.newvalue == "Project B Name" }
if(changeProjectfromTPtoFCN) { issue.setCustomFieldValue(cfAgileTeam, value) }

 

 

It does not give any errors when I move the issue from project A to project B, but it also does not add the value to the "Agile Team" field.

 

Any help is appreciated.

 

Thank you!

Andrew
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 5, 2019

Hi @Mihai Mihai ,

Next work for me:

12345.PNG

Project 'dist' it is target in moving issue. Event - 'Issue Moved'. Project 'source pr' it is source from issue moved.

Code:

 

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

def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def optionsManager = ComponentAccessor.getOptionsManager()

def issue = event.getIssue() as MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()

def customField = customFieldManager.getCustomFieldObject(10600)
def config = customField.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
def optionToSelectA = options.find { it.value == "A" }
log.info(event.getChangeLog().getRelated("ChildChangeItem"))

/* check that issue from SOURCE project */

if (event.getChangeLog().getRelated("ChildChangeItem").find{ it.field == "project" && it.oldstring == "source pr" }){
log.info(issue.getCustomFieldValue(customField))
issuesetCustomFieldValue(customField, optionToSelectA)

issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

}

 

B.R.

Like Mihai Mihai likes this
Mihai Mihai
Contributor
June 6, 2019

Thank you, @Andrew  , this works great!

Suggest an answer

Log in or Sign up to answer