Getting reporter=The reporter specified is not a user when trying to create issues via scriptrunner

Taylor Huston March 31, 2020

Jira v. 8.2.5
ScriptRunner v. 5.6.1.1-jira8

I am trying to write a script that creates some issues under another issue with Scriptrunner. Specifically this function:

 

def createIssue(linkMgr, user, parentIssue, issueService, issueType, summary) {
def asUser = parentIssue.getReporter();
log.warn asUser
def issueInputParameters = issueService.newIssueInputParameters();

issueInputParameters
.setProjectId(parentIssue.projectId)
.setIssueTypeId(issueType.id)
.setSummary(summary)
.setReporterId(asUser.key)


def validationResult = issueService.validateCreate(asUser, issueInputParameters)
if (!validationResult.valid) {
log.error validationResult.errorCollection;
return;
}
def result = issueService.create(asUser, validationResult).issue

linkMgr.createIssueLink(parentIssue.getId(), result.getId(), 10219, 1, asUser);

return result;
}


But that's giving me this output:

2020-03-31 19:38:41,652 WARN [runner.AbstractScriptRunner]: edreimiller@aurora.tech(edreimiller)
2020-03-31 19:38:41,667 ERROR [runner.AbstractScriptRunner]: Errors: {reporter=The reporter specified is not a user.}
Error Messages: []
2020-03-31 19:38:41,668 WARN [runner.AbstractScriptRunner]: edreimiller@aurora.tech(edreimiller)
2020-03-31 19:38:41,675 ERROR [runner.AbstractScriptRunner]: Errors: {reporter=The reporter specified is not a user.}
Error Messages: []

 

I've also tried

def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

and grabbing the user outside of the function and passing it in (hence the 'user' in the function arguments).

Right now I am just prototyping this in Script Console, but this will eventually live in the create Transition of the Workflow.

4 answers

1 vote
sanjay November 2, 2020

Still getting the same error please can anyone solve this ?

Christof Hurst _kreuzwerker_ November 2, 2020

Hi @sanjay , 

With new version of Jira / Scriptrunner you have to use 

.setReporterId(asUser.username)
sanjay November 2, 2020

Thanks @Christof Hurst _kreuzwerker_ 

I will try it again.

sanjay November 2, 2020

Hi @Christof Hurst _kreuzwerker_ 

I have tried but not resolved my error.

 

Here is my Script

 

import com.atlassian.jira.component.ComponentAccessor

// the issue key of the parent issue
final String parentIssueKey = "HC-1"

// the issue type for the new issue - should be of type subtask
final String issueTypeName = "Sub-task"
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// user with that user key will be the reporter of the issue
final String reporterKey =loggedInUser.username

// the summary of the new issue
final String summary = "Test Summary"

// the priority of the new issue
final String priorityName = "Major"

def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
//def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(parentIssueKey)
assert parentIssue : "Could not find parent issue with key $parentIssueKey"

def subtaskIssueTypes = constantsManager.allIssueTypeObjects.findAll { it.subTask }
def subTaskIssueType = subtaskIssueTypes.findByName(issueTypeName)
assert subTaskIssueType : "Could not find subtask issue type with name $issueTypeName. Avaliable subtask issue types are ${subtaskIssueTypes*.name.join(", ")}"

// if we cannot find user with the specified key or this is null, then set as a reporter the logged in user
def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser

// if we cannot find the priority with the given name or if this is null, then set the default priority
def priority = constantsManager.priorities.findByName(priorityName) ?: constantsManager.defaultPriority

def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(parentIssue.projectObject.id)
setIssueTypeId(subTaskIssueType.id)
.setReporterId(loggedInUser.username)
setSummary(summary)
setPriorityId(priority.id)
}

def validationResult = issueService.validateSubTaskCreate(loggedInUser, parentIssue.id, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection

def issueResult = issueService.create(loggedInUser, validationResult)
assert issueResult.valid : issueResult.errorCollection

def subtask = issueResult.issue
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, subtask, loggedInUser)

Christof Hurst _kreuzwerker_ November 2, 2020

This function works:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.*
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult

class XwIssueHelper {

/**
This method creates an issue in the given project with the given issueType, for SubTask the Parent can be hand over as last Parameter
The systemFields map must at least contain values for the keys
- summary
- reporter
optional:
- description
The customFields map has the id of the cf as Long and the value as string
Bsp.:
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def fldsSystem = ["summary": "TEST", "reporter":currentUser.name]
def fldsCustom = [10905L:"123@test.de"]
def prj = 10600L
def issType = "10600"
*/
public static Issue createIssue(ApplicationUser user, Long projectId, String issueTypeId, Map systemfields, Map customFields, Issue parent = null) {
def issueService = ComponentAccessor.issueService
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters
.setProjectId(projectId)
.setIssueTypeId(issueTypeId)
.setSummary(systemfields.summary)
.setReporterId(systemfields.reporter)

if (systemfields.description) {
issueInputParameters.setDescription(systemfields.description)
}

if (systemfields.assignee) {
issueInputParameters.setAssigneeId(systemfields.assignee)
}

if (systemfields.dueDate) {
issueInputParameters.setDueDate(systemfields.dueDate)
}

customFields?.each {
issueInputParameters.addCustomFieldValue(it.key, it.value)
}

CreateValidationResult createValidationResult
if (!parent) {
createValidationResult = issueService.validateCreate(user, issueInputParameters)
} else {
createValidationResult = issueService.validateSubTaskCreate(user, parent.id, issueInputParameters)
}

if (createValidationResult?.isValid()) {
IssueResult createResult = issueService.create(user, createValidationResult)

if (!createResult.isValid()) {
return null
} else {
Issue issue = createResult.issue
if (parent) {
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parent, issue, user)
}
return issue
}
} else {
return null
}
}
}
sanjay November 2, 2020

It is totally different scenario I just want to create Sub-task base on Custom field and link it to parent, its look complex.

Christof Hurst _kreuzwerker_ November 3, 2020

With this method you can do exactly this. Just call it with the correct parameters and a parent id as last parameter. Examples are in the description.

0 votes
sanjay December 16, 2020

Thanks everyone for your valuable time. The issue has been resolved now !

0 votes
Christof Hurst _kreuzwerker_ July 8, 2020

Hi @Taylor Huston , @Eshwar Palem 

With new version of Jira / Scriptrunner you have to use 

.setReporterId(asUser.username)
Juan José Marchal Gómez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2020

It works.

0 votes
Eshwar Palem June 9, 2020

Hi @Taylor Huston,

I am facing the same issue. There is a script in a listener for creating an issue in another project, but it didn't work and thrown error only for a specific issue. Where it says reporter is not a user.

Please let me know about the workaround or fix for this, if you found any.

Suggest an answer

Log in or Sign up to answer