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

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, https://library.adaptavist.com/entity/copy-field-value-from-parent-issue-to-sub-task-upon-creation 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  https://library.adaptavist.com/entity/copy-field-value-from-linked-issue 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)
break

 

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
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

671 views 7 23
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