Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
I am using the Script runner Clone-issue post-function, and in additional actions I want to create Sub-tasks using the contents of a Checkbox. The script works in a "normal" script-runner post-function, but as part of the clone-issue post-function it fails with the following log:
2016-09-27 17:03:03,221 ERROR [utils.ConditionUtils]: Clone issue id = null 2016-09-27 17:03:03,224 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2016-09-27 17:03:03,224 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CR-17, actionId: 121, file: null java.lang.IllegalArgumentException: Parent issue cannot have a null ID. at com.atlassian.jira.issue.IssueImpl.setParentObject(IssueImpl.java:964) at com.atlassian.jira.issue.MutableIssue$setParentObject$4.call(Unknown Source) at Script322$_run_closure1.doCall(Script322.groovy:41) at Script322.run(Script322.groovy:37)
For some reasons, the cloned issue has no id, which have logged (as you can see)
Here is the script:
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.project.Project import groovy.transform.Field import com.atlassian.jira.issue.customfields.option.LazyLoadedOption import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.IssueFactory @Field ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() @Field MutableIssue cloneIssue = issue IssueFactory issueFactory = ComponentAccessor.getIssueFactory() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() def subTaskManager = ComponentAccessor.getSubTaskManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() //name of the custom field def customFieldName = 'Create necessary documentation' //get the custom field object def customFieldObject = customFieldManager.getCustomFieldObjectByName(customFieldName) //get all the values of the custom field def customFieldValues = customFieldObject.getValue(sourceIssue) log.error "Clone issue id = " + issue.id //loop through the values and create sub tasks //change the case value as per requirements such as "Email Required" or "SAP Access Required" customFieldValues.each { LazyLoadedOption it -> def optionValue = it.getValue() MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(optionValue) newSubTask.setParentObject(cloneIssue) newSubTask.setProjectObject(cloneIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) // Add any other fields you want for the newly created sub task log.debug("New issue ${newSubTask}") Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(cloneIssue, newSubTask, user) }
Any clue what I am doing wrong?
Hi Mads,
So at that time the clone Issue is not created and thus the id is null. Therefore there is callback
doAfterCreate = { //do things after the issue creation, like create subtasks }
Is not yet documented but it will be soon (if you use one of the SR 4.* versions)
Also a link to a similar question may help you more https://answers.atlassian.com/questions/39558461
Please let me know if this works for you.
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
UPDATE:
Link to the updated documentation After Create actions
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.