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.

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

845 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you