You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
I' m trying to synchronize the selected options of a Multi-Select field, across linked issues via a ScriptRunner Listner, triggered by the Issue Updated event in a named project.
The link lookup piece is working fine, but I can't crack how to actually update the Multi-select field at the other end of the link. (I can update 'single selects' using a very similar listener, so I'm certain that all works fine) The code below does actually find the options currently selected in the source Multi-select field, but can't transfer them... Based on this post I think I need to get the numeric Ids of the selected options and somehow set them? but 'options.getOptionById' creates errors and seems to be deprecated
(Environment= Jira Software Server 7.12 and SR 5.4.12)
Any advice welcome...
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Logger
import org.apache.log4j.Level
Issue issue = event.getIssue()
def log = Logger.getLogger("com.acme.Customlogger")
log.setLevel(Level.DEBUG)
def linkType = ["Relates"]
def userManager = ComponentAccessor.getUserManager()
def username = "jbloggs" // This user must have permissions in the target project
def user = userManager.getUserByKey(username)
def linkMgr = ComponentAccessor.getIssueLinkManager()
def CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
log.debug "Starting Analysis of Multi Select field"
def cfProgram = cfManager.getCustomFieldObjects(issue).find {it.name == 'Product(s)'} // ** MultiSelect Field
def currentOptions = issue.getCustomFieldValue(cfProgram)?:[]
log.info "currentOptions: " + currentOptions
log.debug("Starting Tests")
if (issue.getIssueType().name == "Change Request") {
log.debug("Found correct issue type - starting loop..")
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
def destIssue = link.getSourceObject() // bind to the originating source of the link
if (linkType.contains(link.issueLinkType.name)) {
destIssue.setCustomFieldValue(cfProgram, [currentOptions])
issueManager.updateIssue(user, destIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
}}}
Paddy,
I received some assistance from @Peter-Dave Sheehan for my question How to copy collection (select, multiselect, radio) values into sub-task(s) within a post-function?
Although my script was for a post-function, the following might be helpful.
// Single select
addCustomFieldValue(inquiryTypeField.id, inquiryTypeValue.optionId as String[]
// Multiselect
addCustomFieldValue(inquiryTypeField.id, inquiryTypeValue*.optionId as String[]
I don't know if this is considered cross-posting, but I spent so much time trying to figure this out, it should be OK include the solution here as well, IMHO.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.