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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,456,714
Community Members
 
Community Events
176
Community Groups

Create issue with IssueService

Edited

Hi guys,

im trying to create a issue based in another issue, see  my script: 

import com.atlassian.jira.component.ComponentAccessor as ca
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult

def issueService = ca.getComponent(IssueService.class)
def issueInputParameters = issueService.newIssueInputParameters();
def userManager = ca.getUserManager()
def issueManager = ca.getIssueManager()
def cfManager = ca.getCustomFieldManager()

def user = ca.getJiraAuthenticationContext().getLoggedInUser()
def issue = issueService.getIssue(user, "SD-455636").getIssue()
def nfeed = cfManager.getCustomFieldObject(18402L)

/*Properties*/
def projectId = issue.projectId
def issueTypeId = issue.issueTypeId
def summary = issue.summary
def reporterId = issue.reporterId
def description = issue.description
def environment = issue.environment
def statusId = issue.statusId
def priorityId = issue.priorityId as String
def resolutionId = issue.resolutionId
def securityLevelId = issue.securityLevelId

/*CustomFields Required*/
def cfCategoria = cfManager.getCustomFieldObject(17500L)
def cfDescCategoria = cfManager.getCustomFieldObject(17501L)
def cfServico = cfManager.getCustomFieldObject(17502L)
def cfTelefoneolicitante = cfManager.getCustomFieldObject(15500L)
def cfUsuarioAtendimento = cfManager.getCustomFieldObject(17800L)

def nfeedXML = nfeed.getValue(issue).split('\n')
def users = []
nfeedXML.each{
if(it.endsWith('</value>'))
users.add(it.substring(it.indexOf(' - ') + 3,it.indexOf('</value>')))
}

users.each{
def u = userManager.getUserByKey(it)
}


try{
issueInputParameters.setProjectId(projectId)
.setIssueTypeId(issueTypeId)
.setSummary(summary)
.setReporterId(reporterId)
.setDescription(description)
.setEnvironment(environment)
.setStatusId(statusId)
.setPriorityId(priorityId)
.setResolutionId(resolutionId)
.setSecurityLevelId(securityLevelId)
.addCustomFieldValue(17500L, cfCategoria.getValue(issue).toString())
.addCustomFieldValue(17501L, cfDescCategoria.getValue(issue).toString())
.addCustomFieldValue(17502L, cfServico.getValue(issue).toString())
.addCustomFieldValue(15500L, cfTelefoneolicitante.getValue(issue).toString())
.addCustomFieldValue(17800L, cfUsuarioAtendimento.getValue(issue).toString())


IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(issue.reporter, issueInputParameters);
if (!createValidationResult.isValid()) {
Map<String, String> errorCollection = createValidationResult.getErrorCollection().getErrors();
log.info("ERROR: Validation errors:");
for (String errorKey : errorCollection.keySet()) {
log.info(errorKey);
log.info(errorCollection.get(errorKey));
}
}
def createResult = issueService.create(issue.reporter, createValidationResult)
log.warn createResult.getIssue()
log.warn createResult
}catch(Exception e){
log.warn "Erro ao criar a issue"
log.error(e)
return null
}

 

This code seems like good, but in atlassian-jira.log dont show me a error and im lost in that problem, anyone can help me what a have to do to resolve the my problem? 

 

Thanks guys.

1 answer

@JonasGomeshow did you solve the error?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events