Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Inheriting Text Field from Parent Issue

Hi All!

I am new to writing scripts with ScriptRunner. Just need a little help!

My Stories roll up to Features in the project that we are using. I have certain fields set to be inherited by the stories from their parent feature upon creation or edit (all of these fields are single select drop down) through Listeners. So if the field on the Feature says NO, so does the field on the Story.

HOWEVER - I have one field that is a text field and I'd like that to inherit from the Feature to the Story upon creation or edit and I cannot figure out how to do it. If someone could help me out with a script that I can throw into a Listener for this, I would be SO grateful! 

Thanks in advance!!

1 answer

0 votes

Yep, is a post-function for doing it on creation of the sub-task, but can easily be modifiied to do it as a listener, or other non-create transitions.

I'm not clear on how you might be relating features to stories

Is it Epic -> Story off-the-shelf, or are Features another layer you're doing with Structure or internal links etc?   This doesn't actually matter for the purpose of me answering the question, it's just saying you might have to think about how you can tell what the relationship is.

If for example, you are using issue links for the relationship, then might be a better starting point than my sub-task creation link above.

And, of course, if it's something else, the rest of the library is worth raiding for more working code (we do test and curate the stuff in the library, unlike my random code snippets I sometimes drop out here in Community)

Hi @Nic Brough _Adaptavist_ Nic! Thanks! Yes, Features are another layer in between Epics and Stories. We use an issue link type to create a parent to child relationship.

However, no such luck. I'm getting error codes thrown at me.

I guess I'm back to the drawing board.

Mmm, that's going to take quite a lot of coding.

What errors are you seeing?

I feel like it shouldn't be this difficult. :) 

All I want to do is pull the text out of a field in one issue and replicate it in another issue in the exact same field based on a link type.

Sorry that "it's going to take a lot of coding" was aimed at the hierarchy thing you're trying to do, not the "copy some text" which is the real point of the question.

What is going wrong when you adapt the script from the library?

switch (fieldToCopyId) {
case fieldManager.&isCustomFieldId:
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
def linkedIssueCustomFieldValue = linkedIssue.getCustomFieldValue(customField)
issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue)


I am getting the following error for the bolded code:

[Static type checking] - Cannot find matching method

com.atlassian.jira.issue.Issue#setCustomFieldValue (com.atlassian.jira.issue   something else that my error box cuts off)

java.lang.Object). Please check if the declared type is correct and if the method exists.

To use setCustomFieldValue(), you need to declare issue as MutableIssue:

import com.atlassian.jira.issue.MutableIssue

(issue as MutableIssue).setCustomFieldValue(customField, linkedIssueCustomFieldValue)

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events