Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Based on some input from a table, have to create JIRA ticket, most of the parameters i am able to fetch, and create the ticket as well. But not able to proceed further while trying to set the component. Here is the code i am using. And below is the exception while trying to set the component value.
import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.mail.Email
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
import java.util.Date
import java.time.*
import java.lang.String
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.project.component.ProjectComponentManager;
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default")
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def project
def issueContext
def priorityId
def issueInputParameters
def validationResult
def issueType
String assignee
def description
// user with that user key will be the reporter of the issue
final reporterKey = 'auser'
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)
def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser
try{
Connection conn1 = ConnectionFactory.getConnection(helperName)
Sql sql2 = new Sql(conn1)
output = sql2.rows("select id, reporter, project, component, summary, description, issuetype, priority, request_dt, status, nvl(assignee,'-1') assignee from tickletTable where status = 'R'")
output.each {
result = it as Map<String,String>
project = ComponentAccessor.projectManager.getProjectObjByKey(result[2])
assert project : "Could not find project with key $projectKey"
issueContext = new IssueContextImpl(project, issueType) as IssueContext
priorityId = constantsManager.priorities.findByName(result[7])?.id ?: prioritySchemeManager.getDefaultOption(issueContext)
issueType = constantsManager.allIssueTypeObjects.findByName(result[6])
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),result[3])
if (component != null)
{
log.warn(" component Found")
issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(result[1])
setSummary(result[4])
setPriorityId(priorityId)
setAssigneeId(result[10])
setDescription(result[5])
setComponent([component])
}
}
else //when no component found for the project
{
issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(result[1])
setSummary(result[4])
setPriorityId(priorityId)
setAssigneeId(result[10])
setDescription(result[5])
}
}
validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection
// def result = issueService.create(loggedInUser, validationResult)
//assert result.valid : result.errorCollection
}
sql2.close()
}
catch(Exception e) {
log.warn( e)
}
Exception :
2021-05-28 08:30:54,108 WARN [runner.ScriptBindingsManager]: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.setComponent() is applicable for argument types: (ArrayList) values: [[ProjectComponentImpl { name='C1', description='C1', lead='', assigneeType='1', projectId='10000', id='10500', archived='false' }]]
To set component in IssueInputParameters, use setComponentIds().
In your case, you use replace:
setComponent([component])
with:
setComponentIds(component)
You should take account of cases with multiple components if applicable.
I hope this helps!
I tried with the
setComponentIds(component)
But i do get the error as mentioned below.
2021-05-31 09:50:16,094 WARN [runner.ScriptBindingsManager]: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.setComponentIds() is applicable for argument types: (com.atlassian.jira.bc.project.component.ProjectComponentImpl) values: [ProjectComponentImpl { name='XYZ', description='XYZ', lead='', assigneeType='1', projectId='10000', id='10500', archived='false' }]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry about that, from the documentation I mentioned, you need to use component id:
setComponentIds(component.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Max
Thanks for the reply, the error doesnt occur anymore, but when the ticket is raised, i dont see the Component getting assigned to the JIRA ticket.
When i print out the component id, i get the id as : [runner.ScriptBindingsManager]: 10500.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.