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
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
Thank you so much. Tried this and it worked like a charm.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@miikhy I have used above code but i am getting issue with
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(field),targetValues)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would need to use something like scriptrunner and create a custom script to make the change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.