Forums

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

How to add custom field values from parent issue into automatic sub- task's summary

Claire Upham
Contributor
January 19, 2018

We would like to  be able to stick custom field values in the summary of an automatic sub- task using the "Create a sub- task" post function. For example, the summary would be:

Add "custom field_1 value" to Work order "custom field_2 value"

Both custom field values would come from the parent issue. Can anyone help with the code that can be used in the "Additional issue actions" of the post- function for this?

1 answer

1 accepted

1 vote
Answer accepted
Jenna Davis
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 19, 2018

Hello Claire, 

You should be able to do something similar to this in the Additional Issue Actions section:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def fieldA = customFieldManager.getCustomFieldObject("FieldA").getValue(sourceIssue)
def fieldB = customFieldManager.getCustomFieldObject("FieldB").getValue(sourceIssue)
issue.summary = "Add ${fieldA} to Work Order ${fieldB}"

You'll need to add in your own custom field names instead of 'FieldA' and 'FieldB'.

I didn't test this directly, so I could've made a typo. Let me know if something doesn't work or if you need any further help. :)

Jenna

Claire Upham
Contributor
January 19, 2018

Hi Jenna,

Thanks for the quick response. I am getting an error message saying "cannot invoke method getValue() on null object"... Is it an issue with this line maybe?

customFieldManager.getCustomFieldObject("FieldA").getValue(sourceIssue)

 Claire

Nic Brough -Adaptavist-
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 19, 2018 edited

It is, that call should be showing an error as the call getCustomFieldManager does not exist.  Try getCustomFieldObjectByName("FieldA")

There's loads of ways to "get" a custom field in CustomFieldManager - I have it bookmarked because I can't remember which is which: https://docs.atlassian.com/software/jira/docs/api/7.6.1/index.html?com/atlassian/jira/issue/CustomFieldManager.html

Claire Upham
Contributor
January 19, 2018

Thanks, Nic. getCustomFieldObjectByName did the trick, it works just as expected.

Thank you both for your help.

Claire

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events