[Script Runner] Copy single select custom field value from issue A to B

Hi there. I have some trouble with getting the value of select CF from issue A and then setting it to the same value on issue B. Here is the failing part of my script:

CustomField CF_pion= customFieldManager.getCustomFieldObject("customfield_13200")
def zawartosc_pion = sourceIssue.getCustomFieldValue(CF_pion)
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
Option option = optionsManager.getOptions(CF_pion.getRelevantConfig(sourceIssue)).getOptionForValue(zawartosc_pion, null);

def changeHolder = new DefaultIssueChangeHolder();
CF_pion.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(CF_pion), option),changeHolder);

Anybody has an idea what is messed up in the above part?

Full script, just in case:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
//import org.apache.log4j.Category
 
MutableIssue issue = issue
//Category log = log
//log.setLevel(org.apache.log4j.Level.DEBUG);
 
def ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = componentManager.getCustomFieldManager();
def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_13305');
def parentTaskID = issue.getCustomFieldValue(parentTaskIDCF);
if (parentTaskID == null || parentTaskID == '') {
    return true;
} else {
    def issueManager = ComponentAccessor.getIssueManager();
    def parentIssue = issueManager.getIssueObject(parentTaskID);
    def isParentIssueValid = (parentIssue != null);
    if (isParentIssueValid) {
        def issueLinkManager = ComponentAccessor.getIssueLinkManager();
        def issueLinkTypeManager = componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class);
        def issueLinkType = issueLinkTypeManager.getIssueLinkTypesByName('Relates').asList()[0];
        def authenticationContext = componentManager.jiraAuthenticationContext;
        issueLinkManager.createIssueLink(issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.getLoggedInUser());

		CustomField CF_lista= customFieldManager.getCustomFieldObject("customfield_13300") 
		CustomField CF_vernazwa= customFieldManager.getCustomFieldObject("customfield_13302") 
		CustomField CF_verid= customFieldManager.getCustomFieldObject("customfield_13301")
		CustomField CF_pion= customFieldManager.getCustomFieldObject("customfield_13200")

		def zawartosc_lista = parentIssue.getCustomFieldValue(CF_lista)
		def zawartosc_vernazwa = parentIssue.getCustomFieldValue(CF_vernazwa)
		def zawartosc_verid = parentIssue.getCustomFieldValue(CF_verid)
		def zawartosc_pion = parentIssue.getCustomFieldValue(CF_pion)
		
		//log.debug zawartosc_lista
		//log.debug zawartosc_vernazwa
		//log.debug zawartosc_verid

		
		
		OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
		Option option = optionsManager.getOptions(CF_pion.getRelevantConfig(parentIssue)).getOptionForValue(zawartosc_pion, null);
		
		def changeHolder = new DefaultIssueChangeHolder();
		CF_lista.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(CF_lista), zawartosc_lista),changeHolder);
		CF_vernazwa.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(CF_vernazwa), zawartosc_vernazwa),changeHolder);
		CF_verid.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(CF_verid), zawartosc_verid),changeHolder);
		CF_pion.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(CF_pion), option),changeHolder);
    }
}

5 answers

This widget could not be displayed.

Any errors in logs? What type of field is it?

This widget could not be displayed.

I'm sorry for the delay, I went for a short vacation :)

The logs threw something like this:

2014-05-22 13:41:01,731 Thread-15557 ERROR bolszyca 820x664857x1 fw6gx6 10.1.3.34 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on OK-17158: C:\Program Files\Atlassian\JIRA\atlassian-jira\skryptyistyle\link_lokalwgsil.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
Possible solutions: getOptionForValue(java.lang.String, java.lang.Long)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
	at javax.script.AbstractScriptEngine.eval(Unknown Source)
	at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
	at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
	at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
	at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564)
	at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:954)
	at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:909)
	at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:450)
	at com.atlassian.jira.bc.issue.IssueService$transition.call(Unknown Source)
	at com.onresolve.jira.groovy.canned.utils.WorkflowUtils.actionIssue(WorkflowUtils.groovy:87)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:43)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.doTransition(FasttrackTransition.groovy:136)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.this$2$doTransition(FasttrackTransition.groovy)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:78)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.this$dist$invoke$1(FasttrackTransition.groovy)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition$1.methodMissing(FasttrackTransition.groovy)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:811)
	at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1103)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1056)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition$1.run(FasttrackTransition.groovy:96)
	at java.lang.Thread.run(Unknown Source)
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
Possible solutions: getOptionForValue(java.lang.String, java.lang.Long)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
	... 43 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
	at Script6.run(Script6.groovy:51)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
	... 44 more

This widget could not be displayed.

I added the log info below, it did not allow me to add more than 2000 chars in comment.

This widget could not be displayed.

I'm sorry for the delay, I went for a short vacation :)

The logs threw something like this:

2014-05-22 13:41:01,731 Thread-15557 ERROR bolszyca 820x664857x1 fw6gx6 10.1.3.34 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on OK-17158: C:\Program Files\Atlassian\JIRA\atlassian-jira\skryptyistyle\link_lokalwgsil.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
Possible solutions: getOptionForValue(java.lang.String, java.lang.Long)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
	at javax.script.AbstractScriptEngine.eval(Unknown Source)
	at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
	at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
	at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
	at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564)
	at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:954)
	at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:909)
	at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:450)
	at com.atlassian.jira.bc.issue.IssueService$transition.call(Unknown Source)
	at com.onresolve.jira.groovy.canned.utils.WorkflowUtils.actionIssue(WorkflowUtils.groovy:87)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:43)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.doTransition(FasttrackTransition.groovy:136)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.this$2$doTransition(FasttrackTransition.groovy)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:78)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition.this$dist$invoke$1(FasttrackTransition.groovy)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition$1.methodMissing(FasttrackTransition.groovy)  <+2>
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:811)
	at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1103)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1056)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.FasttrackTransition$1.run(FasttrackTransition.groovy:96)
	at java.lang.Thread.run(Unknown Source)
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
Possible solutions: getOptionForValue(java.lang.String, java.lang.Long)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
	... 43 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.OptionsImpl.getOptionForValue() is applicable for argument types: (com.atlassian.jira.issue.customfields.option.LazyLoadedOption, null) values: [Hospitality, null]
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
	at Script6.run(Script6.groovy:51)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
	... 44 more

This widget could not be displayed.
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager
import java.sql.Timestamp
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption

class SummaryStatusDate extends AbstractIssueEventListener {
	Logger log = Logger.getLogger(SummaryStatusDate.class)
	@Override
	void workflowEvent(IssueEvent event) {
		log.setLevel(org.apache.log4j.Level.DEBUG)
							
			MutableIssue issue = event.issue
			ComponentManager componentManager = ComponentManager.getInstance()
			def customFieldManager = componentManager.getCustomFieldManager()
			IssueManager issueManager = componentManager.getIssueManager()
			def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "CustomField"}				
			issue.setCustomFieldValue(cf, "new value")
			User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()	
            issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
            issue.store()
		
	}
}

may help

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

94 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you