Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic Issue script

Jorge Alonso Pérez May 28, 2019

 

I want to create a new issue through a script, then a programmed automatic service will execute this script.

I have tested a code of this link (https://scriptrunner.adaptavist.com/latest/jira/recipes/jelly-migration.html#_creating_issues), but an error appears when executing.

My code is:

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("PAN").id
summary = "Issue created from script"
reporterId = user.name
issuetype = "Incident"
}

def validationResult = issueService.validateCreate(user, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()

def issueResult = issueService.create(user, validationResult)
log.info "Issue created: ${issueResult.issue}"


 The error:

assert !validationResult.errorCollection.hasAnyErrors() || | | || | true || Errors: {issuetype=No se ha seleccionado ningún tipo de incidencia.} || Error Messages: [] |com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@14aed94e false

 

Issuetype have assigned the correct parameter in the script but i dont understand the error.

Can anybody help me?

Thanks.

1 answer

1 vote
Antoine Berry
Community Champion
May 28, 2019

Hi @Jorge Alonso Pérez welcome to the community.

You should use the id of the issue type instead of its name : 

issueTypeId = "10100"

Antoine

Jorge Alonso Pérez May 29, 2019

Hi @Antoine Berry !

 

Thanks!! Solved.

I have other question:

I have programmed a daily service to execute the script, in input file I have put the name of the script (example.groovy) and it is saved in (jira/scripts/ xample.groovy) but it does not do anything, the script works from the console but from file not . Can you help me?

Antoine Berry
Community Champion
May 29, 2019

You are welcome ! 

What do you mean by "a daily service" ? Best would be to include a screenshot of your configuration.

Antoine

Jorge Alonso Pérez May 29, 2019

Class: com.onresolve.jira.groovy.GroovyService

Screenshot:

Captura.PNG

Jorge Alonso Pérez May 30, 2019

The script has written in .log, the service does work!!

But the problem is authentication.

The error is: an anonymous user can not create an issue.

Antoine Berry
Community Champion
May 31, 2019

It makes sense since the user to execute the script with is not configured. Please try : 

def user = ComponentAccessor.getUserManager().getUserByKey("berry_a");

instead.

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events