Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

convert a issue to a subtask using scriptrunner for jira cloud

Edited

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()

1 answer

1 accepted

0 votes
Answer accepted

Hi Alex

I can confirm that there is no API to convert an issue into a subtask. You can create the subtask. Here is the documentation on how to create subtask. 

The Build In Create Subtask as documented here which you could add into your workflow onto the Create transition for when the issue is created in order to automatically create the sub-task that you require below the issue. 

The documentation page linked to the Create Subtask post function provides some step by step instructions on how to configure this post function inside of a workflow that you will be able to follow.

I hope this will help.

Thank you

Kate

@Kate Kabir Thank you for the reply. This wasn't exactly what i was hoping for an answer but i figured i could go the create subtask route,

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

548 views 15 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you