Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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!!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mmm, that's going to take quite a lot of coding.
What errors are you seeing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To use setCustomFieldValue(), you need to declare issue as MutableIssue:
import com.atlassian.jira.issue.MutableIssue
(issue as MutableIssue).setCustomFieldValue(customField, linkedIssueCustomFieldValue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.