• Community
  • Products
  • Jira
  • Questions
  • Pull in a custom field value from parent issue in a post-function script on issues creation and set it as part of the summary of the sub-task that is being created in JIRA cloud with ScriptRunner

Pull in a custom field value from parent issue in a post-function script on issues creation and set it as part of the summary of the sub-task that is being created in JIRA cloud with ScriptRunner

What I have determined is a way to pull the result of a custom field from a already created ticket.

 

def issueKey = 'TM-XXX'

def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type''application/json')
        .asObject(Map)
if (result.status == 200){
    return result.body.fields.customfield_10511
else {
    return "Failed to find issue: Status: ${result.status} ${result.body}"
}

Now what I am trying to achieve is create a sub-task using a workflow post function and pull in this custom field from the parent issue and set it as part of the summary of the sub-task that is being created.

 

For example:

I create an issue with a custom field of server name with a value of XXXDC1.

I want to create the subtask.fields.summary that would be XXXDC1 | "and some other text."

1 answer

1 accepted

Hi Marlene,

If you add a "Create Subtask" post function with the following additional code, you can achieve what you've described:

def issueKey = issue.key
def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')
        .queryString('fields', 'customfield_10511')
        .asObject(Map)
if (result.status == 200){
    //return result.body.fields.customfield_10511
    subtask.fields.summary = "${result.body.fields.customfield_10511} | ${subtask.fields.summary}"
} else {
    logger.error("Failed to find issue: ${issueKey}. Status: ${result.status} ${result.body}")
}

I've attached an image here for clarity too:

Screen Shot 2017-03-23 at 09.40.45.png

I hope that helps,
Jon

This was very clear and exactly what I was looking for. Thank you.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

798 views 2 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you