Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner create sub-task with custom field failed

Hi,

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.security.JiraAuthenticationContext;
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 {
setProjectId(parentIssue.projectObject.id)
setIssueTypeId(subTaskIssueType.id)
setReporterId(reporter.key)
setSummary(summary)
setCustomFieldValue(clusterObject,"aaaa")
}

def validationResult = issueService.validateSubTaskCreate(loggedInUser, parentIssue.id, 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=""


test+=i
//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
//cluster
def clusterObject = customFieldManager.getCustomFieldObject("customfield_10501")
newSubtask.setCustomFieldValue(clusterObject,"aaaa")
newSubtask.setProjectId(issueObject.getProjectId())
newSubtask.setIssueTypeId("10300") //issue type id must be subtask type's id
newSubtask.setParentId(issueObject.getId())
//newSubtask.setAssigneeId("user1")
newSubtask.setReporterId(issueObject.getReporterId())
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.

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

All you wanted to know about customer support KPIs

When working in customer support, it’s crucial to calculate, analyze and monitor specific numbers, called KPIs (Key Performance Indicators). They go hand-in-hand with customer satisfaction, problem d...

107 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you