I would like to create a scrip field in User Stories and Tasks to show the value introduced in their parent issue, in my case, the parent issue is a "Requirement" and the field with the information is named "SNOW Number". Could you help me with a script for this?, I know there are already plug ins to do that but I don't want to install another plug in. I already have Scrip Runner plug in installed.
Thanks!
This script should do it.
Create a scripted field with a different name to "SNOW Number" ("All issues SNOW Number" for example)
Make sure you set the "template" for the custom field to the same type of field that your SNOW Number is (number or text), otherwise you'll need a bit more code to convert the output to the template type.
If you're going to be using this field for searching (like "show me all the issues and their sub-tasks with SNOW Number = 42"), then you will need to put the field on the parent issues, and replace the "if issue is not sub-task's "return" with code that returns the SNOW Number from the current issue.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.FieldManager
// the name of the field whose value we want to show on sub-task
final String fieldNameToCopy = "SNOW Number"
FieldManager fieldManager = ComponentAccessor.fieldManager
if (!issue.subTask) {
return
}
def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
if (!fieldToCopy) {
log.info "Could not find field with name $fieldNameToCopy"
return
}
def parentIssue = issue.parentObject
def fieldToCopyId = fieldToCopy.id
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
return parentIssue.getCustomFieldValue(customField)
Thanks for the information, I tried with your solution but It returns null all the time for issues that I know have information in SNOW Number field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, find an issue that has a SNOW number, go into the script editor for the field, and try putting the issue key into the test box. The tab beneath it will show you the execution log, including errors.
I'd add a bit more logging in:
if (!issue.subTask) {
log.info "Not a sub-task"
return
}
...
log.info customField
return parentIssue.getCustomFieldValue(customField)
Once we've found the problem, you'll want to remove those logs to avoid performance issues and filling your logs with unneeded lines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have been using this script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem in your code is that you are getting the parent issue type, not the actual parent issue, but see my answer for a different way to do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.