I am trying to clone an issue to another project and also set the Flagged custom field to "Impediment" on the cloned issue:
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def cf = customFieldManager.getCustomFieldObjectByName("Flagged") def fieldConfig = cf.getRelevantConfig(issue) def optionsManager = ComponentAccessor.getOptionsManager() def value = optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Impediment' } issue.setCustomFieldValue(cf, value)
When I execute this code, I see an exception in the JIRA logs:
2016-03-29 15:42:34,210 http-bio-8080-exec-13 ERROR matt_shelton 942x5658x1 iod9tz 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: CAPD-31, actionId: 1, file: null com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:757) at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:645) at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:770) at com.atlassian.jira.issue.IssueManager$createIssueObject$0.call(Unknown Source) at com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:96) at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.super$2$doScript(CopyIssueWithAttachments.groovy) at com.onresolve.scriptrunner.canned.jira.utils.CopyIssueWithAttachments.doScript(CopyIssueWithAttachments.groovy:10) at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.super$3$doScript(CloneIssue.groovy) at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.doScript(CloneIssue.groovy:85) Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:923) at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:746) ... 8 more Caused by: java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:41) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:854) at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:88) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446) at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615) at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:886) ... 9 more
Based on the exception, I suspect the issue here is how I'm populating value
, but I don't know how else to get it. The line in question was based on this answer, but I may be misunderstanding it.
Thanks!
The error is here:
Caused by: java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection
This is because Flagged is (normally) a check box field and takes a Collection of Option objects.
So changing the last line to:
issue.setCustomFieldValue(cf, [value])
should work.
Attempting to get value this way also does not work, despite this being, I think, the more direct route:
def value = optionsManager.getOptions(fieldConfig).getOptionById(10000)
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.