Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Values not copied into subtask via postfunction

Sander Spoelstra
Contributor
January 16, 2023

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.

2023-01-16 16_01_23-[ITS-15004] After creating subtasks in LPTAM-ticket some fields must be copied f.png

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. 

1 answer

1 accepted

0 votes
Answer accepted
Naveen Kumar_Appfire
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 17, 2023

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

Sander Spoelstra
Contributor
January 18, 2023

2023-01-18 09_42_59-You do not have permission to view this request. - Jira Service Management.png

 

I am not able to view that support ticket.

Naveen Kumar_Appfire
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 19, 2023

Hi @Sander Spoelstra

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 

Sander Spoelstra
Contributor
February 10, 2023

The bug was fixed and the values are now copied correctly

Suggest an answer

Log in or Sign up to answer