I am attempting to set the value on a multiselect custom field through scriptrunner.
I have tried multiple options based on suggestions from the community - however none of them seem to work properly.
log.info "Updating Target Issue Project Board"
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(targetProjectBoardField.getRelevantConfig(newIssueObject));
log.info "Available Options: " + options
Option newOption = options.getOptionById(Long.parseLong(affectedBoardsFieldValue));
log.info "Identified Option: " + newOption
def fieldConfig = targetProjectBoardField.getRelevantConfig(newIssueObject)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.optionId.toString().trim() == affectedBoardsFieldValue.toString().trim() }
log.info "Final Value:" + value
def changeHolder = new DefaultIssueChangeHolder()
def issueCustomFieldValues = newIssueObject.getCustomFieldValue(targetProjectBoardField)
log.info "issueCustomFieldValues: "+issueCustomFieldValues
ModifiedValue mVal = new ModifiedValue(issueCustomFieldValues, value)
log.info "mVal: "+mVal
newIssueObject.setCustomFieldValue(targetProjectBoardField, [value])
newIssueObject.store()
log.info "Target Issue Project Board has been updated."
log.info "Validation - " + newIssueObject.getCustomFieldValue(targetProjectBoardField)
This shows the following log:
2018-10-18 14:23:28,126 INFO [jira.groovy]: Updating Target Issue Project Board
2018-10-18 14:23:28,126 INFO [jira.groovy]: Available Options: [AAA, BBB]
2018-10-18 14:23:28,126 INFO [jira.groovy]: Identified Option:AAA
2018-10-18 14:23:28,128 INFO [jira.groovy]: Final Value:Agile Workforce
2018-10-18 14:23:28,128 INFO [jira.groovy]: issueCustomFieldValues: [XXX]
2018-10-18 14:23:28,128 INFO [jira.groovy]: mVal:com.atlassian.jira.issue.ModifiedValue@ecdf7a
2018-10-18 14:23:28,129 INFO [jira.groovy]: Target Issue Project Board has been updated.
2018-10-18 14:23:28,129 INFO [jira.groovy]: Validation - [AAA]
The log shows that the issue is being updated successfully, However when I go to the issue, it still reflects the old value XXX
Another options is:
log.info "Updating Target Issue Project Board"
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(targetProjectBoardField.getRelevantConfig(newIssueObject));
log.info "Available Options: " + options
Option newOption = options.getOptionById(Long.parseLong(affectedBoardsFieldValue));
log.info "Identified Option: " + newOption
ModifiedValue mVal = new ModifiedValue(newIssueObject.getCustomFieldValue(targetProjectBoardField), newOption);
targetProjectBoardField.updateValue(null, newIssueObject, mVal, new DefaultIssueChangeHolder());
log.info "Target Issue Project Board has been updated."
log.info "Validation - " + newIssueObject.getCustomFieldValue(targetProjectBoardField)
This throws the following error:
ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: JIRA-849, actionId: 111, file: <inline script>
java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.MultiSelectCFType.valuesEqual(MultiSelectCFType.java:90)
at com.atlassian.jira.issue.fields.ImmutableCustomField.valuesEqual(ImmutableCustomField.java:1575)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:424)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)
at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)
Can someone help me fix this and get it working properly?
I found it - enclosing the newOption within a collection did the trick.
ModifiedValue mVal = new ModifiedValue(newIssueObject.getCustomFieldValue(targetProjectBoardField), [newOption]);
Hello Sree,
can you please paste the full script?
thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
log.info "Updating Target Issue Project Board"
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(targetProjectBoardField.getRelevantConfig(newIssueObject));
log.info "Available Options: " + options
Option newOption = options.getOptionById(Long.parseLong(affectedBoardsFieldValue));
log.info "Identified Option: " + newOption
def fieldConfig = targetProjectBoardField.getRelevantConfig(newIssueObject)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.optionId.toString().trim() == affectedBoardsFieldValue.toString().trim() }
log.info "Final Value:" + value
def changeHolder = new DefaultIssueChangeHolder()
def issueCustomFieldValues = newIssueObject.getCustomFieldValue(targetProjectBoardField)
log.info "issueCustomFieldValues: "+issueCustomFieldValues
ModifiedValue mVal = new ModifiedValue(newIssueObject.getCustomFieldValue(targetProjectBoardField),[newOption])
log.info "mVal: "+mVal
newIssueObject.setCustomFieldValue(targetProjectBoardField, [value])
newIssueObject.store()
log.info "Target Issue Project Board has been updated."
log.info "Validation - " + newIssueObject.getCustomFieldValue(targetProjectBoardField)
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.