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.
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome !
What do you mean by "a daily service" ? Best would be to include a screenshot of your configuration.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.