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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,799 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot