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.
Hi Manju,
Answered to you in your original question. https://answers.atlassian.com/questions/45393907
Please create new threads only for different questions.
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 ->
MutableIssue 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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Thanos Batagiannis [Adaptavist]
I am able to clone issues as per the above code. But they are being with the created date of the parent issues. Is it the expected behavior?
Or is there anyway to change created date to current date?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.