I am Trying to clone issue(s) based on the number of a "custom field" values updated in a parent issue in a Custom script post-function as below::
I am getting the following error, using JIRA version 6.7.16 and script runner version 4.1.3.16.
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 Script1433$_run_closure1.doCall(Script1433.groovy:89) at Script1433.run(Script1433.groovy:69)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.MutableIssue
Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//assuming this is a multiple select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted Sub-Systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)
/*
The following Required fields for creating a issue/clone has to be copied from parent to clone while clone issue creation....
Customer, Customer impact, Defect Source, Priority, Requirement id, Server Component, Server Release, Server Release tag, Severity, Test Case id.
'Customer' is a "Select List (single choice)"
'Customer impact' is a "Select List (single choice)"
'Defect Source' is a "Select List (single choice)"
'Priority' is a "Jira default field"
'Requirement id' is a "Text Field (multi-line)"
'Server Component' is a "Select List (single choice)"
'Server Release' is a "Select List (single choice)"
'Server Release tag' is a "Select List (single choice)"
'Severity' is a "Select List (single choice)"
'Test Case id' is a "Text Field (multi-line)"
*/
def Customer = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer")
def selectedCustomer = issue.getCustomFieldValue(Customer)
def CustomerC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer")
def CustomerImp = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer impact")
def selectedCustomerImp = issue.getCustomFieldValue(CustomerImp)
def CustomerImpC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer impact")
def defectsource = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
def selecteddefectsource = issue.getCustomFieldValue(defectsource)
def defectsourceC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
def Priority = issue.getPriority()
def Severity = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")
def selectedSeverity = issue.getCustomFieldValue(Severity)
def SeverityC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")
def Requirementid = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirement id")
def selectedRequirementid = issue.getCustomFieldValue(Requirementid)
def RequirementidC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirement id")
def ServerComponent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Component")
def selectedServerComponent = issue.getCustomFieldValue(ServerComponent)
def ServerComponentC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Component")
def ServerRelease = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release")
def selectedServerRelease = issue.getCustomFieldValue(ServerRelease)
def ServerReleaseC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release")
def ServerReleasetag = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release tag")
def selectedServerReleasetag = issue.getCustomFieldValue(ServerReleasetag)
def ServerReleasetagC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release tag")
def TestCaseid = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Case id")
def selectedTestCaseid = issue.getCustomFieldValue(TestCaseid)
def TestCaseidC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Case id")
//assuming this is a single choice 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)
// set the value of the custom sub-system and any other issue parameters you wish (project, assignee, etc)
//copying the "Impacted Sub-Systems" parent custom field values one by one into "Subsystem" custom field value of clone issue(s).
newIssue.setCustomFieldValue(subSystemCF, it.value)
newIssue.setCustomFieldValue(CustomerC, selectedCustomer)
newIssue.setCustomFieldValue(CustomerImpC, selectedCustomerImp)
newIssue.setCustomFieldValue(defectsourceC, selecteddefectsource)
//newIssue.setCustomFieldValue(PriorityC, selectedPriority)
newIssue.setPriority(Priority)
newIssue.setCustomFieldValue(SeverityC, selectedSeverity)
newIssue.setCustomFieldValue(RequirementidC, selectedRequirementid)
newIssue.setCustomFieldValue(ServerComponentC, selectedServerComponent)
newIssue.setCustomFieldValue(ServerReleaseC, selectedServerRelease)
newIssue.setCustomFieldValue(ServerReleasetagC, selectedServerReleasetag)
newIssue.setCustomFieldValue(TestCaseidC, selectedTestCaseid)
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}
Which version of JIRA do you have? 6.7.16 is probably the version of JIRA Agile you have.
Anyway it looks like you are creating the cloned issue wrong. There is quite a few parts to it.
In my opinion you are best off using the "clone issue" post-function for this which is under "script post-functions".
Your "additional issue actions" should be the following which will clear out those fields you don't want to copy over:
def fieldName = 'MyCustomField' def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == fieldName} issue.setCustomFieldValue(cf, null)
You can even set a condition to only clone when certain fields have been changed for example to check a field contains "Some Value":
cfValues['Some Custom Field'] == 'Some Value'
You can find the full documentation here.
Hope this helps.
Hi Adam,
Thanks for your prompt response.
I would like to clone "multiple JIRA issues" based on the parent issue's custom field values(if there are 3 values updated in 'Impacted sub-systems' field, 3 clones has to be created. If it's 4, 4 clones to be created, etc) as I shared it before.
So I can't use "clone issue" post-function(i,e Clones an issue and links) for this which is under "script post-functions" as it creates only one Clone issue from the parent.
The below one is my exact requirement, which is posted in productsupport.adaptavist.com.
If my parent issue custom field value (i,e field data type is Select List (multiple choices)] is updated with Mobile, Desktop, Hybrid values - I would like to create 3 clones with these values updates into Cloned PRs respectively. means
As parent issue custom field(i,e Impacted sub-systems') has 3 values, I need to create 3 Clones isuses in total from the parent JIRA issue and
1st cloned "sub-system" custom field to be updated with = Mobile (i,e fist value of Impacted sub-systems to be set)
2nd cloned "sub-system" custom field = Desktop (i,e Second value of Impacted sub-systems to be set)
3rd cloned "sub-system" custom field = Hybrid (i,e Third value of Impacted sub-systems to be set)
Except the "sub-system" custom field value in Clone PRs, all other default and custom field values should be copied from the parent to all Cloned issue as it is.
Please suggest how this can be achieved using the currently provided Script workflow function : Clones an issue and links in Script runner OR Script Post-Function -> Custom script post-function using inline script tried/posted above?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I do the transition of parent issue from "Eng Assgin to Eng Fixed", on post successful transition to Eng Fixed, I will create the "number of Clone issues" in post function based on the 'Impacted sub-systems' values updated by the parent JIRA issue Assignee.
But the below required fields has to be copied into cloned issue from the parent as my create transition mandates it along with overwriting the sub-system custom field value in clone issue from the parent issue Impacted sub-system field values one by one as shared it previously.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adam - Based on the response from Thanos Batagiannis [Adaptavist], was trying to use/modify the inline script posted in my previous to previous post.
As per Thanos , For a JIRA v7, it's written as below and same has been modified to suite my requirement and was getting the errors like
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 Script1433$_run_closure1.doCall(Script1433.groovy:89) at Script1433.run(Script1433.groovy:69)
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()
//assuming this is a multiple select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(
"Component CF"
)
def selectedComponents = issue.getCustomFieldValue(componentCF)
//assuming this is a text custom field
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(
"sub-system"
)
selectedComponents?.each { LazyLoadedOption it ->
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)
// set the value of the custom sub-system and any other issue parameters you wish (project, assignee, etc)
newIssue.setCustomFieldValue(subSystemCF, it.value)
Map<String,Object> newIssueParams = [
"issue"
:newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Manju,
Answered to you in your original question. https://answers.atlassian.com/questions/45393907
Please create new threads only for different questions.
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.