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
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

1,164 views 4 5
Join discussion

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