Recently i ran into a dilemma. I am trying to take a issue that is created and convert it to a subtask of a different parent issue as part of a postfunction.
I was able to script a way to generate the key for the parent issue using the following code. In Jira we have the option to convert a issue to a subtask. The code below generates my parent ticket id as the queuedissueparent. What would need to be done to take a task and then convert it to a subtask that is linked to the queuedissueparent?
// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
// get issue type
def issuetype = get("/rest/api/2/issue")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def projectKey = issue.fields.project.key
def inputprojecttype = customFields.find { it.name == 'PIA Project' }?.id
def input1 = issue.fields[inputprojecttype] as String
if (input1 != 'UNKNOWN') {
if (input1 == 'Rapid Design Engagement') {
def queuedissueparent = 'BPIA-1132'
}
else
if (input1 == 'Fixed Wireless') {
def queuedissueparent = 'BPIA-1133'
}
else
if (input1 == 'Head End') {
def queuedissueparent = 'BPIA-1134'
}
else
if (input1 == 'Conduit Design') {
def queuedissueparent = 'BPIA-1135'
}
else
if (input1 == 'Subdivision GIS Design') {
def queuedissueparent = 'BPIA-1136'
}
else
if (input1 == 'Business Readiness') {
def queuedissueparent = 'BPIA-1137'
}
else
if (input1 == 'OSP') {
def queuedissueparent = 'BPIA-1138'
}
else
if (input1 == 'Confluence Space Standardization') {
def queuedissueparent = 'BPIA-1139'
}
else
if (input1 == 'Contracts') {
def queuedissueparent = 'BPIA-1140'
}
else
if (input1 == 'Change Orders') {
def queuedissueparent = 'BPIA-1141'
}
else
if (input1 == 'Department User Dashboards') {
def queuedissueparent = 'BPIA-1142'
}
else
if (input1 == 'Departmental Dashboards') {
def queuedissueparent = 'BPIA-839'
}
else
if (input1 == 'EPP') {
def queuedissueparent = 'BPIA-1143'
}
else
if (input1 == 'Feasibility') {
def queuedissueparent = 'BPIA-368'
}
else
if (input1 == 'Member Dashboards') {
def queuedissueparent = 'BPIA-1145'
}
else
if (input1 == 'Member Project Information Updates') {
def queuedissueparent = 'BPIA-1161'
}
else
if (input1 == 'Regional Dashboards') {
def queuedissueparent = 'BPIA-1146'
}
else
if (input1 == 'Revamp the PIA Request Process') {
def queuedissueparent = 'BPIA-1147'
}
else
if (input1 == 'IMS Training Process Documentation') {
def queuedissueparent = 'BPIA-1144'
}
else
if (input1 == 'IMS Member Rollout') {
def queuedissueparent = 'BPIA-197'
}
}
I think the link would be done using the following code. I am just not positive how to actually convert a issue to a subtask using scriptrunner for jira cloud.
// link issue block of code
// Specify the source issue
final sourceIssueKey = issue.fields.key
// Specify the target issue
final targetIssueKey = 'queuedissueparent'
// Specify the link type to use
final linkType = "Relates"
// issue link
def link = post('/rest/api/2/issueLink')
.header('Content-Type', 'application/json')
.body([
type: [ name: linkType ],
outwardIssue: [ key: sourceIssueKey ], // This is the issue that the link 'starts' at.
inwardIssue: [ key: targetIssueKey ] // This is the issue that the link 'finishes' at.
])
.asString()