I'm trying to have a transition that creates a new linked issue in another project that has different required fields (workflow validators via JSU) that the original issue doesn't have data for. I am attempting to use the built in Scriptrunner post function that "Clones an issue, and links".
For this, I turned to the Additional issue actions section to write code to pre-populate/hard-code values I want to set for the newly created linked issue but am running into problems getting it to accept values for a Cascading Select List custom field which is required in the new project.
I've used the optionsManager class to successfully get the options/optionIDs from the field configuration, but cannot get the issue created when trying to update/add the values into the new issue. I've tried various methods from setCustomFieldValue and updateValue to no avail (commented out in the code below):
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
log.setLevel(Level.INFO)
log.setLevel(Level.DEBUG)
// get custom fields for destintion request
def assignmentGroup = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Assignment Group'}
def optionsManager = ComponentAccessor.optionsManager
def productCat = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Product categorization'}
def changeHolder = new DefaultIssueChangeHolder()
def productCatFieldConfig = productCat.getRelevantConfig(issue)
def productOptions = optionsManager.getOptions(productCatFieldConfig)
log.info("productCatFieldConfig: " + productCatFieldConfig)
def productCatValue1 = productOptions.find {it.value == 'Infrastructure'}
def productCatValue2 = productCatValue1?.childOptions?.find {it.value == 'CLAN'}
log.info("productCatValue1 & 2: " + productCatValue1 + " - " + productCatValue2)
//productCat.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(productCat),[productCatValue1,productCatValue2]),changeHolder)
//productCat.setFormValue([productCatValue1.optionId, productCatValue2.optionId])
issue.setCustomFieldValue(assignmentGroup, 'JIRA-IS')
//issue.setCustomFieldValue(productCat, productCat.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(productCat),productCatValues),changeHolder))
log.debug("we made it here")
//productCat.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(productCat),productCatValues),changeHolder)