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

Error while trying to set component from Groovy

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' }]]

2 answers

1 accepted

0 votes
Answer accepted

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' }] 

sorry about that, from the documentation I mentioned, you need to use component id:

setComponentIds(component.id)
Like Nagappan Murugappan likes this

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.

Thanks Max it worked. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

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