createIssueObject() after cloneIssue() in my Inline groovy script is not working as expected

Hi,

In my inline script createIssueObject() after cloneIssue() created is not working as expected - please advice why? using this inline script in my Script Post-Function -> Custom script post-function

I am using JIRA version 6.7.16 and Script runner version 4.1.3.16.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//'Impacted sub-systems' is a multiple choice select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)

//'Subsystem' is a Single choice select list custom field
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem")

selectedComponents?.each { LazyLoadedOption it ->
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)

newIssue.setCustomFieldValue(subSystemCF, it.value)

Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>

issueManager.createIssueObject(currentUser, newIssueParams)
//issueManager.createIssueObject(currentUser, newIssue)
}

Error:

Only one clone issue is created eventhough I had given 3 string values as part of the "Impacted sub-systems" custom field and throwing error @ line, selectedComponents?.each { LazyLoadedOption it -> (i,e

groovy:110) and @ line, issueManager.createIssueObject()(i,e groovy:82) as below::
2017-01-09 16:29:07,397 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-01-09 16:29:07,397 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INT-1691, actionId: 131, file: <inline script>
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$1.call(Unknown Source)
	at Script1741$_run_closure1.doCall(Script1741.groovy:110)
	at Script1741.run(Script1741.groovy:82)
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)
	... 5 more

 

Please advice anything wrong in the above Groovy Inline script using.

  • Manju

 

2 answers

0 vote
Vasiliy Zverev Community Champion Jan 09, 2017

I refactored your code, tri it:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField

//Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//'Impacted sub-systems' is a multiple choice select list custom field
CustomField componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)

//'Subsystem' is a Single choice select list custom field
CustomField subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem")

IssueManager issueManager = ComponentAccessor.getIssueManager()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
selectedComponents?.each { Option it -&gt;
    
    MutableIssue newIssue = issueFactory.cloneIssue(issue)

    newIssue.setCustomFieldValue(subSystemCF, it.value)

    Map&lt;String,Object&gt; newIssueParams = ["issue":newIssue] as Map&lt;String,Object&gt;

    issueManager.createIssueObject(currentUser, newIssueParams)
//issueManager.createIssueObject(currentUser, newIssue)
}

Hi Manju,

Answered to you in your original question. https://answers.atlassian.com/questions/45393907

Please create new threads only for different questions. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

801 views 3 11
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