Hello everyone,
I am trying to create a new issue by groovy script in post function. I added all necessary fields but when I execute validateCreate function I received the error:
Error Messages: [Summary: You must specify a summary of the issue.
My code is:
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "[Rel Request]" )
.setDescription(transitionComment)
.setIssueTypeId(issueTypeID)
.setPriorityId(parentPriority)
.setReporterId(reporterID)
.setAssigneeId(assigneeID)
log.error("Summary: " + issueInputParameters.getSummary())
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)
if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueResult createResult = issueService.create(
user, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
What's the error? Anybody can help me?
Thank you guys.
Hello @luanlopes94
I check your code in script console and it work perfectly
Are you sure that other parameters is not nulls?
There example of code i check
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DS-2")
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "[Rel Request]" )
.setDescription("test desc")
.setIssueTypeId(issue.issueTypeId)
.setPriorityId(issue.priorityId)
.setReporterId(issue.reporterId)
.setAssigneeId(issue.assigneeId)
log.error("Summary: " + issueInputParameters.getSummary())
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService.CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)
if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueService.IssueResult createResult = issueService.create(
user, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
Mark,
Thank you for the tip. I detected a problem with setIssueTypeId. I am trying to pass a custom issue type by parameter like this:
def issueTypeID = "10013"
But, not working. If a use issue.issueTypeId it's work correctly. Do you know the correct way to pass issue type information?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I check code with declaration like in your case and it work:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
def issueTypeID = "10103"
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DS-2")
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "[Rel Request]" )
.setDescription("test desc")
.setIssueTypeId(issueTypeID)
.setPriorityId(issue.priorityId)
.setReporterId(issue.reporterId)
.setAssigneeId(issue.assigneeId)
log.error("Summary: " + issueInputParameters.getSummary())
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService.CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)
if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueService.IssueResult createResult = issueService.create(
user, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
Please check that issue type with given id exist, and .setIssueTypeId() need id as string object, may be there some problem with groovy cast dynamic types.
Try to declare it directly :
String issueTypeID = "10013"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error is the same with String object:
Summary: You must specify a summary of the issue.
Issue types exists and I am passing a String to setIssueTypeId().
I don't know :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to log everything and see thats all parameters correct:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import org.apache.commons.lang3.StringUtils
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
def issueTypeID = "10103"
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DS-2")
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "[Rel Request]" )
.setDescription("test desc")
.setIssueTypeId(issueTypeID)
.setPriorityId(issue.priorityId)
.setReporterId(issue.reporterId)
.setAssigneeId(issue.assigneeId)
log.error("Summary: " + issueInputParameters.getSummary())
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService.CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)
log.error("issue input parameters: " + issueInputParameters.getActionParameters())
if (createValidationResult.isValid())
{
log.error("entrou no createValidationResult")
IssueService.IssueResult createResult = issueService.create(
user, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
else
{
String cause = StringUtils.join(createValidationResult.getErrorCollection().getErrorMessages(), "/")
log.error("cause :" + cause)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Mark,
Now the error is more specific:
2018-06-11 13:45:56,004 ERROR [workflow.ScriptWorkflowFunction]: Errors: {issuetype=The issue type selected is invalid.}
But, I am still with no solution :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmm, may be this issue type is subtask type?:)
For subtasks use
validateSubTaskCreate instead of validateCreate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This issue type is normal task, not subtask.
The problem only occur when a set other value in IssueTypeId.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I give up :)
There is obviously some problem with issue type.
Try to create issue with another issueTypeId. Need some research :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, this is an issue type problem.
Other issue type works correctly :)
Mark, thanks for your time. I will verify the issue type restrictions/validations.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thats right!
Do you try to create that issue type manually?
Anyways if you find out the problem, let me know :) Im curious.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I try to create manually this error occur:
THIS TASK (SUB-TASK) TYPE IS NOT ALLOWED!
try to create from parent workflow button
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @luanlopes94
If you have script runner plugin installed, then instead of writing the groovy scirpt, you can use the built-in function "clone issue" to create an issue with customized data and fields.
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.
Tarun,
I can't use scriptrunner because my script needs to consume a rest service provided by a custom plugin.
Thank you for the tip.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.