Here is the code in scriptrunner:
// Specify the key of the parent issue here
def parentKey = 'FN-29722'
// Get the parent issue type
def issueResp = get("/rest/api/2/issue/${parentKey}")
.asObject(Map)
assert issueResp.status == 200
// get the body of the parent issue type
def issue = issueResp.body as Map
// Get the issue types for the instance
def typeResp = get('/rest/api/2/issuetype')
.asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>
// Here we set the basic subtask issue details
def summary = "DEV::BATCH - test" // The summary to use for
def issueType = "Sub-task" // The Sub Task Issue Type to Use
// Get the sub task issue type to use
def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
assert issueTypeId : "No subtasks issue type found called '${issueType}'"
// Get the project to create the subtask in
def project = (issue.fields as Map).project
// Create the subtask
def resp = post("/rest/api/2/issue")
.header("Content-Type", "application/json")
.body(
fields: [
project: project,
issuetype: [
id: issueTypeId
],
parent: [
id: issue.id
],
summary: summary
])
.asObject(Map)
// Get and validate the newly created subtask
def subtask = resp.body
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
// If the sub task created successfully return a success message along with its key
if (resp.status == 201) {
return 'Success - Sub Task Created with the key of ' + resp.body.key.toString()
} else {
return "${resp.status}: ${resp.body}"
}
Here is the error:
Serializing object into 'interface java.util.Map'
GET /rest/api/2/issue/FN-29722 asObject Request Duration: 659ms
Serializing object into 'interface java.util.List'
GET /rest/api/2/issuetype asObject Request Duration: 316ms
Serializing object into 'interface java.util.Map'
POST /rest/api/2/issue asObject Request Duration: 564ms
POST request to /rest/api/2/issue returned an error code: status: 400 - Bad Request
body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
Assertion failed:
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
| | | | | | | | |
| 400 true | | 400 false false false
| | status: 400 - Bad Request
| | body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
| false
status: 400 - Bad Request
body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
Class: com.adaptavist.sr.cloud.events.ConsoleScriptExecution, Config: [userTriggered:true]
Hello Kevin.
Yes this is entirely possible using a postfunction.
In the simplest case, let's say that you want to copy the original issue to the Epic and then to the task.
You would need to:
-----------------------
1. Go to your workflow.
2. Edit your workflow.
3. Go to the transition that you want this to trigger on:
4. Add Scriptrunner postfunction.
5. Select Copy Issue and Links postfunction.
6. Select the fields that you want to propagate to the next issue, for example
a) Description
b) Version number
7. Select the issue type as an Epic.
8. Save the postfunction and move it to the last place in the list of postfunctions in your transition.
-----------------------
Repeat this process for your other
(task) Desgin Product X
(task) Build Product X
(task) Test Procuts X
BUT bear in mind to set the issue type as "Subtask" or "Task"
In the end you would have a total of 4 postfunctions. The first one would be for your epic, and the rest for your design, build and test steps.
Please do say if I can be of anymore help.
Cheers!
Dyelamos
Hi Daniel,
This is a great soltuon.
Thanks for your help on this
Kevin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem. Could you please accept my answer so that other users know that this has been correctly answered?
Thanks!
DYelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daniel Yelamos [Adaptavist] I don't see Select Copy Issue and Links within workflow postfunction.
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.