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!
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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mihai Mihai ,
Next work for me:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.