What I try to do is copy values from certain custom fields into a subtask. The subtask is created via ScriptRunner during a transition. Based on the value of the field 'environment' (multi-select), the script creates a subtask for every value of that field.
However, in that script I am unable to set / copy values from custom fields. I have only been able to set values for fixed fields. As such, I have created a second post function (JSU addon this time) in which I try to copy the value of three custom fields into the subtask.
This however does not result in the fields being filled on the subtask. I also tried moving around the order of post functions, for example, to first run the update change history and even the re-index before copying fields into the subtask. Nothing seems to work. In all cases, the subtask lets me know that the field is present in the project, ticket type, screen etc., but it has not value.
Note that the value is known on the parent ticket before the transition is done and the subtasks are created.
The full script that I use for the subtask creation is:
// Imports
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.priority.Priority
// import for debug only
import org.apache.log4j.Logger
import org.apache.log4j.Level
log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
//Current issue - uncomment for post-function
Issue parentIssue = issue
//Get Value of Environment
CustomFieldManager cFM = ComponentAccessor.getCustomFieldManager()
String Environment = 'customfield_12090'
CustomField customfield_Env = customFieldManager.getCustomFieldObject(Environment)
Object customfieldIDValue_Env = (ArrayList) parentIssue.getCustomFieldValue(customfield_Env)
//Pre-define JQL Parser functions
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def activeUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Pre-define Sub-Task Generation functions
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def dueDate = parentIssue.getDueDate()
def project = parentIssue.getProjectObject()
def description = parentIssue.getDescription()
def priority = parentIssue.getPriority()
def component = parentIssue.getComponents()
def reporter = parentIssue.getReporter()
def parentSummary = parentIssue.getSummary()
//Get Value of Release
def release = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_17392")
def releaseValue = issue.getCustomFieldValue(release)
log.warn(releaseValue)
//Iterate through and create subtasks
if("Yes" == releaseValue.getValue()){
log.warn(releaseValue.getValue())
for (int i = 0; i < customfieldIDValue_Env.size(); i++){
def summary = parentSummary + " - " + customfieldIDValue_Env.get(i)
def environment = customfieldIDValue_Env.get(i)
//Create core Sub-Task Values
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setProjectObject(project)
newSubTask.setReporter(reporter)
if (issue.projectObject.key == 'CICD' | issue.projectObject.key == 'KC' | issue.projectObject.key == 'LPTAM') {
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Simplified - Release"}.id)
log.warn(issue.projectObject.key)
}
else {
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Axon Delivery - Release subtask"}.id)
log.warn(issue.projectObject.key)
}
newSubTask.setParentObject(parentIssue)
newSubTask.setSummary(summary)
newSubTask.setDescription(description)
newSubTask.setDueDate(dueDate)
newSubTask.setComponent(component)
newSubTask.setPriority(priority)
newSubTask.setReporter(activeUser)
//Create Sub-Task
def newIssueParams = ["issue" : newSubTask] as Map
def createdSubTask = issueManager.createIssueObject(activeUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, createdSubTask, activeUser)
}
}
p.s. I've tried to work with the newSubTask.setCustomFieldValue() but this gave an error I couldn't resolve.
Hi Sander,
Thank you for raising the support request with us.
This is Naveen from Appfire Support team. To better track your request, we have created a support ticket in our portal SUPPORT-58796: Values not copied into subtask via postfunctionWORK IN PROGRESS. Please sign in and access the ticket and let us know if you have any other questions or concerns about the information provided in the ticket.
Thanks,
Naveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As we have made you a reporter to the issue. Could you please sign up to check the issue https://appfire.atlassian.net/servicedesk/customer/portal/11/SUPPORT-58796
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The bug was fixed and the values are now copied correctly
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.