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.
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)
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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Taylor Huston , @Eshwar Palem
With new version of Jira / Scriptrunner you have to use
.setReporterId(asUser.username)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.