Hi, I'm trying to work out why the below script isn't working. I'm trying to update two custom fields as part of a post function:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def scrapCf = customFieldManager.getCustomFieldObjectByName("Country")
def fieldConfig = scrapCf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("UK", null)
issue.setCustomFieldValue(scrapCf, option)
def scrapCf = customFieldManager.getCustomFieldObjectByName("City")
def fieldConfig = scrapCf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("London", null)
issue.setCustomFieldValue(scrapCf, option)
checkAttachment = {attachment -> false};
issue.assigneeId = null;
Hi Daniel,
I guess you are trying to update a Select list (single choice) custom field ?
This piece of code should do the trick :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def scrapCf = customFieldManager.getCustomFieldObjectByName("Country")
def currentValue = issue.getCustomFieldValue(scrapCf)
def fieldConfig = scrapCf.getRelevantConfig(issue)
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == "UK" }
scrapCf.updateValue(null, issue, new ModifiedValue(currentValue, option), new DefaultIssueChangeHolder())
issue.store()
issueIndexingService.reIndex(issue)
Regards,
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.