Hi Community!
I am trying to create subtasks for an issue, in a Service Management project as a post function during create transition. It is based on a multi select custom field, so that one subtask is to be created for each selected item.
However the script runs into a permission error when a user outside of the service management group is trying to create the issue.
Heres the simplified script:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
//get technical user
def techUser = ComponentAccessor.getUserManager().getUserByName("techuser")
// the priority of the new issue
def priorityName = issue.priority.getName()
def issueService = ComponentAccessor.getIssueService()
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.key)
def subTaskIssueType = constantsManager.getIssueType('11101')
//set reporter as reporter of sub-tasks
def reporter = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def priorityId = constantsManager.priorities.findByName(priorityName)?.id
String subSummary = "subSummary"
String subDescription = "subDescription"
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.setProjectId(parentIssue.projectObject.id)
issueInputParameters.setIssueTypeId(subTaskIssueType.id)
issueInputParameters.setReporterId(reporter.username)
issueInputParameters.setSummary(subSummary)
issueInputParameters.setPriorityId(priorityId)
issueInputParameters.setDescription(subDescription)
def validationResult = issueService.validateSubTaskCreate(techUser, parentIssue.id, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection
def issueResult = issueService.create(techUser, validationResult)
assert issueResult.valid : issueResult.errorCollection
//set issue parent - sub-task link
def subtask = issueResult.issue
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, subtask, techUser)
In addition to what @Nic Brough -Adaptavist- stated - Another thing for you to consider is not assigning the issue.
Best, Joseph Chung Yin
Jira/JSM Functional Lead, Global Infrastructure Applications Team
Viasat Inc.
Thanks Joseph!
I forget this option a lot, I usually work with Jira systems that globally require someone to own each issue (it's a good practice to have a single point of contact/whinging/failure), and hence can't leave the assignee blank.
But no assignee would also solve your problem. As long as you tell your people that they need to be looking at them as well as what they are assigned to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Nic Brough -Adaptavist- and @Joseph Chung Yin for your answers. The techuser is an agent so that shouldn't be a problem. Also I don't see where the assigning happens with this script. There is no issueinputparameter for an assignee. However I also tried to include it with null value to handle it by JIRA automatically when creating issues manually, but the result is still the same. So what did you mean by trying to not assign the issue in this case?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suspect you have set the assignee mandatory, or set the "do not allow unassigned issues", so the project requires an assignee, but the test user does not have "assign issue" permission.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I create the issue with an agent it stays unassigned, so that's what bothers me, that it is allowed to be unassigned.
Anyway, in the meantime I found a "solution":
ApplicationUser technicalUser = ComponentAccessor.getUserManager().getUserByName("techuser")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(technicalUser)
def techUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
This sets the loggedinuser to the techuser which is an agent, so the permission problem does not exist anymore.
Thanks for your answers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code looks fine to me, I think it's what it mentions in the error message - test_user does not have "assign issues" permission in the project.
As a JSM project, it might not be just that - I cannot remember the exact rules, but in JSM projects, only Agents can do some things, and I think assigning issues may be one of them.
If that is the case, then you have three options:
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.