Forums

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

Groovy to create Issue with defined creator

Martin Wassink May 17, 2019

Hello everyone,

I am trying to create a new issue by groovy script in post function.
The ticket creator should be a defined "system"-user who has the rights to create tickets.
We include this in the creation, but the current user will continue to be used as ticket creator.
Therefore we get problems with the permissions, because only the system-user has rights for issue create.

Code snipe:

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
ApplicationUser system = ComponentAccessor.getUserManager().getUserByKey("system")

issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "Test" )
.setDescription("Test description")
.setIssueTypeId(issueTypeID)
.setPriorityId(parentPriority)
.setReporterId(reporterID)
.setAssigneeId(assigneeID)

CreateValidationResult createValidationResult = issueService.validateCreate(system, issueInputParameters)

if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(system, createValidationResult)
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}


Does anyone have any idea?

Thank you and best regards,

Martin

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Champion
May 17, 2019

Hi @Martin Wassink ,

I would suggest to change the logged in user at execution time : 

ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(system)

That did the trick for me.

Antoine

Martin Wassink May 17, 2019

Hi @Antoine Berry ,

fine, that works for me!!! 

Thank you very much,

Martin

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer