Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

Still getting the same error please can anyone solve this ?

Hi @sanjay , 

With new version of Jira / Scriptrunner you have to use 

.setReporterId(asUser.username)

Thanks @Christof Hurst _kreuzwerker_ 

I will try it again.

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)

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
}
}
}

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

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.

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.

Hi @Taylor Huston , @Eshwar Palem 

With new version of Jira / Scriptrunner you have to use 

.setReporterId(asUser.username)

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you