Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner create sub-task with custom field failed

Priska Aprilia October 23, 2019


I am trying to create a sub-task with custom fields.
I can create sub-task with system fields with the following code. However, whenever I add the line of code for setting custom field, an error is returned like below. Note that Cluster is a textfield.

No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.setCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField, java.lang.String) values: [Cluster, aaaa]

And this is my code. I have tried to look online to find a solution. You can see, I did try another method in the commented codes but to no avail. Please help. Thanks

import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonSlurper
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters.addCustomFieldValue.*
import com.atlassian.jira.issue.fields.CustomField;

def cfm = ComponentAccessor.customFieldManager
def issueKey = "CSDA-47"
def issueManager = ComponentAccessor.getIssueManager()
def issueObject = issueManager.getIssueByCurrentKey("CSDA-47")
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def authenticationContext = ComponentAccessor.getJiraAuthenticationContext();

import com.atlassian.jira.component.ComponentAccessor

// the issue key of the parent issue
final String parentIssueKey = "CSDA-47"

// the issue type for the new issue - should be of type subtask
final String issueTypeName = "VM Sub-task"

// user with that user key will be the reporter of the issue
final String reporterKey = "anuser"

// the summary of the new issue
final String summary = "Groovy Friday"

def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(parentIssueKey)
assert parentIssue : "Could not find parent issue with key $parentIssueKey"

def cVMDetails = customFieldManager.getCustomFieldObject("customfield_10401")
assert parentIssue : "Could not find parent issue with id $customfield_10401"
def cVMDetailsValue = parentIssue.getCustomFieldValue(cVMDetails)

def subtaskIssueTypes = constantsManager.allIssueTypeObjects.findAll { it.subTask }
def subTaskIssueType = subtaskIssueTypes.findByName(issueTypeName)
assert subTaskIssueType : "Could not find subtask issue type with name $issueTypeName. Avaliable subtask issue types are ${subtaskIssueTypes*.name.join(", ")}"

def jsonSlurper = new JsonSlurper()
def json_object = jsonSlurper.parseText(cVMDetailsValue.toString())
assert json_object instanceof Map : "Not a JSON"
int size = json_object.rows.size()
// if we cannot find user with the specified key or this is null, then set as a reporter the logged in user
def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser
for(int i;i<size;i++){
def clusterObject = customFieldManager.getCustomFieldObjectByName("Cluster")
def issueInputParameters = issueService.newIssueInputParameters().with {

def validationResult = issueService.validateSubTaskCreate(loggedInUser,, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection

def issueResult = issueService.create(loggedInUser, validationResult)
assert issueResult.valid : issueResult.errorCollection

def subtask = issueResult.issue
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, subtask, loggedInUser)

def user = authenticationContext.getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()

def test=""

//create new issue as sub task
def newSubtask = issueFactory.getIssue()
newSubtask.summary = "new subtask"+i;
def network_tier = json_object.rows[i].columns.network_tier
//def network_tier = json_object.rows[i].columns.network_tier
newSubtask.description = "Network Tier: " + network_tier
def clusterObject = customFieldManager.getCustomFieldObject("customfield_10501")
newSubtask.setIssueTypeId("10300") //issue type id must be subtask type's id
newSubtask = issueManager.createIssueObject(user, newSubtask)

//link subtask to parent task
def subTaskManager = ComponentAccessor.getSubTaskManager()
subTaskManager.createSubTaskIssueLink(issueObject, newSubtask, user)



1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 24, 2019

Hi @Priska Aprilia , 

Looking at your logs and at the javadoc, it seems that you should use addCustomFieldValue instead of setCustomFieldValue.


AUG Leaders

Atlassian Community Events