Inheriting Text Field from Parent Issue

Laci January 5, 2021

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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 5, 2021

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)

Laci January 11, 2021

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 12, 2021

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

What errors are you seeing?

Laci January 13, 2021

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2021

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?

Laci January 13, 2021

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.

Max Lim _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 16, 2021

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
AUG Leaders

Atlassian Community Events