Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create sub-task with a summary based on a custom field

Becky Simpkins December 7, 2020

Hi!  I am using Scriptrunner to create a sub-task via a workflow postfunction.  My goal is to end up with a sub-task that's summary field is a combination of the parent's summary and the contents of a custom field.  For example, the sub-task's summary field would look like this:

[Parent's summary field] - [Contents of a select list custom field]

Anyone know how to put that in groovy?  

Thanks for your help!

1 answer

0 votes
Max Lim _ScriptRunner_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2021

Navigate > Add post function > Script Post-Function [ScriptRunner] > Create a sub-task

Fill in appropriate configurations, and under _Additional issue actions_:

import com.atlassian.jira.component.ComponentAccessor

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Just text").first()
def parentIssue = issue.getParentObject()

issue.setSummary(parentIssue.getSummary() + "-" + parentIssue.getCustomFieldValue(customField))

 Hope this helps.

Becky Simpkins February 1, 2021

Thanks for the reply!  I tried the above but received the following error:

 

2021-02-01 13:57:07,159 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue NAM-3960 for user 'becky'. 
java.util.NoSuchElementException: Cannot access first() element from an empty List
 at Script78.run(Script78.groovy:8)

 

Any idea what the problem might be?  Ok if not.  My team ended up deciding not to carry the Summary field from the parent over to the child.  So asking this question in the hopes of helping someone else in the future.  :)

Max Lim _ScriptRunner_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2021

The error occurs because you did not have a "Just text" custom field in your parent issue.

You need to replace "Just text" with the name of your intended select list custom field name.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events