How to bulk edit one value in a multi-select Field

Robert Brown May 15, 2019

Hey all,

I have a user that wants to change just one value in a custom multi-select list. That value is no longer valid and they want to replace it with another. I was planning to use Bulk Edit, but I want to make sure that I don't affect any other values that may have been selected.

Essentially it is a find/replace bulk edit on a certain value multi-select field, leaving all other selections alone. The standard Bulk Edit seems to just replace whatever was there with the new value.

Thanks

-Rob

3 answers

1 accepted

1 vote
Answer accepted
miikhy
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.
May 16, 2019

Hey Rob!

Here is a piece of script I used to solve a similar problem:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.*
import com.atlassian.jira.issue.util.*
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.bc.issue.search.SearchService

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
def query = jqlQueryParser.parseQuery("INSERT MEANINGFUL JQL HERE") // Add JQL!!
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

results.getResults().each {documentIssue ->

def issue = issueManager.getIssueObject(documentIssue.id)
def field = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_XXXXX") // change XXXXX with CF ID
def fieldConfig = field.getRelevantConfig(issue)
def targetValues = []

for(val in issue.getCustomFieldValue(field)) {
if(val.toString() != 'My Value to Replace') {
targetValues += ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find {
it.value == val.toString()
}
} else {
targetValues += ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find {
it.value == 'My New Value'
}
}
}
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(field),targetValues)
field.updateValue(null, issue, mVal, new DefaultIssueChangeHolder())

}

Hope this helps!

Cheers

Robert Brown May 16, 2019

Thank you so much. Tried this and it worked like a charm.

Teja June 24, 2020

@miikhy Where do we need to place this script? We have scriptrunner app.

Regads

Tejas

miikhy
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 24, 2020

Hi @Teja ,

You might use this code directly within Script Runner's console!

You can find it by browsing the App tab of the admin section of Jira, and search for "Script Console". Don't forget to change the parameters :)

Cheers

0 votes
jaya chandra reddy nellore September 13, 2023

@miikhy I have used above code but i am getting issue with 

ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(field),targetValues)

Screenshot (13).png 

0 votes
Brant Schroeder
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2019

You would need to use something like scriptrunner and create a custom script to make the change.

Suggest an answer

Log in or Sign up to answer