Hello,
I would like the field "Verteilung" in Sub-Task to always be up to date, because the same field in parent tends to change from time to time and we need them synced. All that would be easy with scripted field but the field is actually type Select List (single choice) for which there is no custom template, at least I didn't find anything on it so far on google. Is this possible at all?
Cheers,
Rok
@Jeremy Gaudet's answer is interesting, just in case it's not clear he uses the exact same custom field between parent and child, therefore you can use simple JQL to search for either parents or children.
In answer to the specific question, you could just return the string value of the option, and use the plain text template.
This is all depends what you are trying to achieve. If it's searching subtasks, I would use jql:
issueFunction in subtasksOf("Verteilung = Foo") (... and subtask clauses)
If it's about drawing attention to an attribute of the parent issue on a subtask, I would use a script field.
I decided to go for return the string value of the option and to use the plain text template. I know it should be easy, but I am beginner in Scriptrunner sadly, what am I doing wrong? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def Verteilung = getCustomFieldValue("Verteilung").toString() return Verteilung ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// PS: Verteilung field in the parent is Select List (single choice) type
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I thought it was on the parent? You are looking for a field on the current issue there. issue.parentObject.getCustomField( cf ) Look in other questions for how to get a custom field by name using CustomFieldManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In fact there is an example in Jeremy's answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've actually tried this with a scripted field, and it's messy because you then have to search using two different fields, the source field for the parent, and the separate scripted field for the child. Syncing can be accomplished using a script listener that looks for changes to the parent that include the field and then updates the children. Here is code I use to sync two fields, a custom field called "Verified Version/s" and the normal "Fix Version/s" field. The listener is on all events that could change the field... Issue Updated, Issue Resolved, etc.
package com.myorg.listeners import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.issue.Issue import com.atlassian.jira.project.version.Version import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.event.type.EventDispatchOption import java.util.ArrayList import java.util.Collection class SyncParentFixVerifiedVersionsToSubTask extends AbstractIssueEventListener { Category log = Category.getInstance(SyncParentFixVerifiedVersionsToSubTask.class); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager(); Boolean changed = false; @Override void workflowEvent(IssueEvent event) { try { if (subTaskManager.isSubTasksEnabled()) { Issue eventIssue = event.getIssue(); Collection<Issue> subTasks = eventIssue.getSubTaskObjects(); if ( !eventIssue.getIssueTypeObject().isSubTask() ) { List changeItems = event.getChangeLog().getRelated("ChildChangeItem"); if( changeItems.any {it.get('field')=='Fix Version'} ) { changed = true; Collection<Version> fixVersions = new ArrayList<Version>(); fixVersions = eventIssue.getFixVersions(); if (!subTasks.isEmpty()) { subTasks.each { it.setFixVersions(fixVersions); } } } if( changeItems.any {it.get('field')=='Verified Version/s'} ) { changed = true; CustomField vvcf = customFieldManager.getCustomFieldObjectByName("Verified Version/s"); Collection<Version> verifiedVersions = new ArrayList<Version>(); verifiedVersions = eventIssue.getCustomFieldValue(vvcf); if (!subTasks.isEmpty()) { subTasks.each { it.setCustomFieldValue(vvcf,verifiedVersions); } } } if (changed) { subTasks.each { issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false); } } } } } catch (ex) { log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by SyncParentFixVerifiedVersionsToSubTask" log.debug (ex.getMessage()) } } }
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.