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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

ScriptRunner create sub-task with custom field failed


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

0 votes
Antoine Berry Community Leader Oct 24, 2019

Hi @Priska Aprilia , 

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


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events